React
ProseKit has first-class support for React via prosekit/react.
Provider
Section titled “Provider”<ProseKit editor={editor}> provides context to its descendants. The component itself does not render any DOM, it only forwards children.
All hooks are exported from prosekit/react.
useEditor
Section titled “useEditor”Read the editor instance from the nearest <ProseKit> provider. The returned reference is stable; for UI that depends on editor state, use useEditorDerivedValue.
useEditorDerivedValue
Section titled “useEditorDerivedValue”Compute a value from the editor and re-render whenever the editor state changes. Memoise derive (or define it outside the component), since it's used as the dependency key for the underlying store.
useExtension
Section titled “useExtension”Register an extension for the lifetime of the calling component. When extension changes (or becomes null), the previous one is removed and the new one is added. Useful for features that turn on/off conditionally.
useKeymap
Section titled “useKeymap”Bind a keymap for the lifetime of the calling component.
useDocChange
Section titled “useDocChange”Run handler whenever the editor's document changes. The handler receives the current document node. Use editor.getDocJSON() from inside if you need JSON.
useStateUpdate
Section titled “useStateUpdate”Same as useDocChange but fires on every state update, including selection changes and cursor moves. Use this for selection-sensitive UI that doesn't need to wait for document edits.
Custom node and mark views
Section titled “Custom node and mark views”defineReactNodeView
Section titled “defineReactNodeView”Render a node with a React component. ReactNodeViewProps exposes node, view, getPos, setAttrs, decorations, and selected.
defineReactMarkView
Section titled “defineReactMarkView”Same as defineReactNodeView but for marks.
See also
Section titled “See also”- The Editor concept page
- Extensions & union
- Components: pre-built React components for toolbar, inline menu, slash menu, and friends.
prosekit/reactreference- Minimal example
- Full-featured example