This page is available as Markdown at /api/editor/functions/useeditorselector.md. For the full documentation index, see /llms.txt, or the complete corpus at /llms-full.txt.
useEditorSelector
useEditorSelector<
TSelected>(editor,selector,compare?):TSelected
Defined in: packages/editor/src/editor/editor-selector.ts:42
Hook to select a value from the editor state.
Type Parameters
Section titled “Type Parameters”TSelected
Section titled “TSelected”TSelected
Parameters
Section titled “Parameters”editor
Section titled “editor”selector
Section titled “selector”EditorSelector<TSelected>
compare?
Section titled “compare?”(a, b) => boolean
Returns
Section titled “Returns”TSelected
Examples
Section titled “Examples”Pass a selector as the second argument
import {useEditor, useEditorSelector} from '@portabletext/editor'import {getActiveStyle} from '@portabletext/editor/selectors'
function MyComponent() { const editor = useEditor() const activeStyle = useEditorSelector(editor, getActiveStyle)}Pass an inline selector as the second argument. In this case, use the editor context to obtain the schema.
import {useEditor, useEditorSelector} from '@portabletext/editor'
function MyComponent() { const editor = useEditor() const schema = useEditorSelector(editor, (snapshot) => snapshot.context.schema)}