From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
  • Plate
  • Plitev42
    • Editor API
    • Editor Transforms
    • Node
    • Element
    • Text
    • Path
    • Point
    • Range
    • Location
    • Location Ref
    • Document Change
  • Plate Core
    • Plate Components
    • Plate Editor
    • Plate Plugin
    • Plate Store
    • Plate Controller
  • Plate Utils
  • React Utils
  • cn
  • Floating
  • Resizable

Store

PreviousNext

API reference for Plate store.

Plate is using jotai-x to store the state of the editor.

Plate Store

The PlateStoreState object stores React shell state around a Plate editor: the editor reference, container refs, mounted state, renderer fallbacks, and decorations. Commit callbacks are Plate props, not mutable store state.

Plate PluginPlate Controller

On This Page

Plate StoreAccessing the StoreStore HooksusePlateStateusePlateValueusePlateSetEvent Editor StoreuseEventPlateId
Build your editor
Production-ready AI template and reusable components.
Get all-access

State

    Plate editor reference. Plate keeps a stable inert editor internally while a controller has no active editor so hook subscriptions retain their call shape. Public editor hooks do not expose that internal value: useEditor() requires an active provider and useActiveEditor() returns null when no editor is active.

    A reference to the Plate shell container element.

    Function used to decorate ranges in the editor.

    (options: { editor: PlateEditor; entry: NodeEntry }) => Range[]
    (options: { editor: PlateEditor; entry: NodeEntry }) => Range[]

    Whether Editable is rendered so Plite DOM is resolvable.

    Whether the editor is primary. If no editor is active, then PlateController will use the first-mounted primary editor.

    • Default: true

    Function to render elements in the editor.

    Function to render leaf nodes in the editor.

    Function to render text nodes in the editor.

Accessing the Store

import { useEditorPlugin, usePlateStore } from 'platejs/react'
 
// Direct store access
const store = usePlateStore(id?) 
 
// Via the plugin portal
const store = useEditorPlugin(myPlugin).store
import { useEditorPlugin, usePlateStore } from 'platejs/react'
 
// Direct store access
const store = usePlateStore(id?) 
 
// Via the plugin portal
const store = useEditorPlugin(myPlugin).store

Note: The id parameter is optional and defaults to the closest editor.

Store Hooks

The following hooks are available to interact with the Plate store:

import { usePlateState, usePlateValue, usePlateSet } from 'platejs/react'
import { usePlateState, usePlateValue, usePlateSet } from 'platejs/react'

usePlateState

Get and set a store property value.

const [readOnly, setReadOnly] = usePlateState('readOnly', id?)
const [readOnly, setReadOnly] = usePlateState('readOnly', id?)

usePlateValue

Subscribe to a store property value.

const readOnly = usePlateValue('readOnly', id?)
const readOnly = usePlateValue('readOnly', id?)

usePlateSet

Set a store property value.

const setReadOnly = usePlateSet('readOnly', id?)
const setReadOnly = usePlateSet('readOnly', id?)

Event Editor Store

This store is an object whose property keys are event names (e.g. 'focus') and whose property values are editor IDs.

  • This is useful when having multiple editors and get one based on DOM events (e.g. the last focused editor).
  • One of the core plugins of Plate will store the following events.

State

    Last editor ID that has been blurred.

    Editor ID that is currently being focused.

    Last editor ID.

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')
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')

useEventPlateId

Get the last event editor ID.

Parameters

    Returned ID if defined.

Returnsstring

    The plate id from the context if available, otherwise the last event editor ID or PLATE_SCOPE.