Skip to content

Editor API Overview

The editor API provides access to the editor context and selectors for deriving state.

Use the following hooks to access the editor from within your components.

useEditor

Access the editor context. Commonly used when building toolbars or passing context to selectors.

import {useEditor} from '@portabletext/editor'
const editor = useEditor()

useEditorSelector

Access selectors in areas where the context is unavailable by combining with useEditor.

import {useEditor, useEditorSelector} from '@portabletext/editor'
import * as selectors from '@portabletext/editor/selectors'
const editor = useEditor()
const isActive = useEditorSelector(editor, selectors.isActiveDecorator('em'))