Skip to main content

StateConfig

class

The return value of createState, for use with $getState and $setState.

class StateConfig<K extends string | symbol, V>

Import

import { StateConfig } from '@modular/sdk/editor';

Members7

defaultValue
V

The result of `stateValueConfig.parse(undefined)`, which is computed only once and used as the default value. When the current value `isEqual` to the `defaultValue`, it will not be serialized to JSON.

isEqual
(a: V, b: V) => boolean

An equality function from the StateValueConfig, with a default of Object.is.

key
K

The string key used when serializing this state to JSON

parse
(value?: unknown) => V

The parse function from the StateValueConfig passed to createState

resetOnCopyNode
boolean
schemaoptional
AnySerializationSchema

The SerializationSchema for this state's value, present when its `parse` is a schema (e.g. `createState('mode', {parse: enumValue([...])})`). It exposes the value's introspectable domain so tooling such as `@lexical/fast-check` can generate examples of this state. It is undefined when `parse` is a plain function with no schema metadata.

unparse
(value: V) => unknown

The unparse function from the StateValueConfig passed to createState, with a default that is simply a pass-through that assumes the value is JSON serializable.