Views
A view customizes how the editor renders a node or mark in the DOM. For most schemas the toDOM you wrote in the spec is enough. Reach for a view when you need:
- Interactive content (buttons, inputs, dropdowns inside a node).
- Live data (an embed that fetches metadata, a widget that updates on selection changes).
- Per-instance state that ProseMirror's selection model can't express.
Node views
Section titled “Node views”defineNodeView takes a name and a ProseMirror NodeViewConstructor.
In practice you'll almost always use the framework wrapper instead of the raw helper. Each integration ships a define<Framework>NodeView that lets you write the view as a component:
| Framework | Wrapper |
|---|---|
| React | defineReactNodeView |
| Vue | defineVueNodeView |
| Preact | definePreactNodeView |
| Svelte | defineSvelteNodeView |
| Solid | defineSolidNodeView |
ReactNodeViewProps (and its peers in other frameworks) gives you node, view, getPos, setAttrs, decorations, and selected.
Mark views
Section titled “Mark views”defineMarkView and define<Framework>MarkView do the same job for marks. Use them sparingly, since most marks are perfectly served by a toDOM in the mark spec.
A typical use case is a comment or annotation mark that needs a popover when its text is selected.
Decorations
Section titled “Decorations”Decorations sit on top of the document without changing the schema. They're great for showing collaborator cursors, search highlights, or inline error squiggles. Decorations live inside ProseMirror plugins; register them with definePlugin.
The Plugin, Decoration, and DecorationSet imports come from prosekit/pm, which re-exports the underlying ProseMirror packages.
When not to reach for a view
Section titled “When not to reach for a view”- If the only goal is custom CSS, pass a
class:attribute fromtoDOMinstead. - If the goal is a non-editable pill (e.g., a chip), see if a regular inline node with
atom: trueis enough. - If you need to render React/Vue/etc. outside the document (a toolbar, a slash menu), use a normal component from Components. Node views are only for in-document UI.