docs/api/core/plate-store.mdx
Plate is using jotai-x to store the state of the editor.
createPlateFallbackEditor()
</APIItem>
(options: { editor: PlateEditor; entry: NodeEntry }) => TRange[]
(options: { editor: PlateEditor; value: ValueOf<PlateEditor> }) => void
(options: { editor: PlateEditor; selection: TSelection }) => void
(options: { editor: PlateEditor; value: ValueOf<PlateEditor> }) => void
(options: {
editor: PlateEditor;
node: Descendant;
operation: NodeOperation;
prevNode: Descendant
}) => void
Parameters:
editor: The Plate editor instancenode: The node after the operationoperation: The node operation that occurred (insert, remove, set, merge, split, move)prevNode: The node before the operationNote: For insert_node and remove_node operations, both node and prevNode contain the same value to avoid null cases.
</APIItem>
(options: {
editor: PlateEditor;
node: Descendant;
operation: TextOperation;
prevText: string;
text: string
}) => void
Parameters:
editor: The Plate editor instancenode: The parent node containing the text that changedoperation: The text operation that occurred (insert_text or remove_text)prevText: The text content before the operationtext: The text content after the operation
</APIItem>
true
</APIItem>
import { usePlateStore, useEditorRef, useEditorPlugin } from 'platejs/react'
// Direct store access
const store = usePlateStore(id?)
// Via editor reference
const store = useEditorRef().store
// Via plugin context
const store = useEditorPlugin(myPlugin).store
Note: The id parameter is optional and defaults to the closest editor.
The following hooks are available to interact with the Plate store:
import { usePlateState, usePlateValue, usePlateSet } from 'platejs/react'
Get and set a store property value.
const [readOnly, setReadOnly] = usePlateState('readOnly', id?)
Subscribe to a store property value.
const readOnly = usePlateValue('readOnly', id?)
Set a store property value.
const setReadOnly = usePlateSet('readOnly', id?)
This store is an object whose property keys are event names (e.g. 'focus') and whose property values are editor IDs.
Last editor ID that has been blurred.
</APIItem> <APIItem name="focus" type="string | null">Editor ID that is currently being focused.
</APIItem> <APIItem name="last" type="string | null">Last editor ID.
</APIItem> </APIState> </API>import { EventEditorStore, useEventEditorValue } from 'platejs'
// Get a value
const focusedId = EventEditorStore.get('focus')
// Set a value
EventEditorStore.set('focus', editorId)
// Subscribe to changes
const focusedId = useEventEditorValue('focus')
useEventPlateIdGet the last event editor ID.
<API name="useEventPlateId"> <APIParameters> <APIItem name="id" type="string | null">Returned ID if defined.
</APIItem> </APIParameters> <APIReturns type="string"> The plate id from the context if available, otherwise the last event editor ID or `PLATE_SCOPE`. </APIReturns> </API>