Skip to main content

$getState

function

The accessor for working with node state. This will read the value for the state on the given node, and will return `stateConfig.defaultValue` if the state has never been set on this node. The `version` parameter is optional and should generally be NODE_STATE_LATEST, consistent with the behavior of other node methods and functions, but for certain use cases such as `updateDOM` you may have a need to use NODE_STATE_DIRECT to read the state from a previous version of the node. For very advanced use cases, you can expect that NODE_STATE_DIRECT does not require an editor state, just like directly accessing other properties of a node without an accessor (e.g. `textNode.__text`).

function $getState<K extends string, V>(node: LexicalNode, stateConfig: StateConfig<K, V>, version?: NodeStateVersion): V

Import

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

Notes

returns
The current value from the state, or the default value provided by the configuration.