Skip to content

EditorEventListener

EditorEventListener(props): null

Defined in: packages/editor/src/plugins/plugin.event-listener.tsx:55

Listen for events emitted by the editor. Must be used inside EditorProvider. Events available include:

  • ‘blurred’
  • ‘done loading’
  • ‘editable’
  • ‘error’
  • ‘focused’
  • ‘invalid value’
  • ‘loading’
  • ‘mutation’
  • ‘patch’
  • ‘read only’
  • ‘ready’
  • ‘selection’
  • ‘value changed’

Parameters

props

on

(event) => void

Returns

null

Examples

Listen and log events.

import {EditorProvider} from '@portabletext/editor'
import {EventListenerPlugin} from '@portabletext/editor/plugins'
function MyComponent() {
return (
<EditorProvider>
<EventListenerPlugin
on={(event) => {
console.log(event)
}
} />
{ ... }
</EditorProvider>
)
}

Handle events when there is a mutation.

<EventListenerPlugin
on={(event) => {
if (event.type === 'mutation') {
console.log('Value changed:', event.snapshot)
}
}}
/>