Skip to main content

$setState

function

Set the state defined by stateConfig on node. Like with `React.useState` you may directly specify the value or use an updater function that will be called with the previous value of the state on that node (which will be the `stateConfig.defaultValue` if not set). When an updater function is used, the node will only be marked dirty if `stateConfig.isEqual(prevValue, value)` is false.

function $setState<Node extends LexicalNode, K extends string, V>(node: Node, stateConfig: StateConfig<K, V>, valueOrUpdater: ValueOrUpdater<V>): Node

Import

import { $setState } from '@modular/sdk/editor';

Notes

example
```ts const toggle = createState('toggle', {parse: Boolean}); // set it direction $setState(node, counterState, true); // use an updater $setState(node, counterState, (prev) => !prev); ```
returns
node