Build React Node Views
mainTo create custom node views using React components, pass your components to the nodeViewComponents prop of the ProseMirror component.
Requirements for Node View Components:
- Ref Forwarding: Components must pass their
refto their top-level DOM element. - Content DOM: Components that render
childrenmust passnodeProps.contentDOMRefto the parent element of those children. - Props: Components receive
NodeViewComponentProps, which includesnodeProps(containingnode,getPos,decorations, andcontentDOMRef).
Node View Hooks:
useNodePos(): Returns the current position of the node. Note: Only use this in callbacks or effects; using it in render will not trigger re-renders on position changes.useIsNodeSelected(): Returnstrueif the node is currently selected.useIsComposingIn(): Returnstrueif an IME composition is active inside the node.useStopEvent(handler): Registers astopEventhandler.useIgnoreMutation(handler): Registers anignoreMutationhandler.useSelectNode(selectNode, deselectNode): Registers selection handlers.