@blocknote/react
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
24 lines (20 loc) • 649 B
text/typescript
import type { BlockNoteEditor } from "@blocknote/core";
import { useEffect } from "react";
import { useBlockNoteContext } from "../editor/BlockNoteContext.js";
export function useEditorChange(
callback: Parameters<BlockNoteEditor<any, any, any>["onChange"]>[0],
editor?: BlockNoteEditor<any, any, any>,
) {
const editorContext = useBlockNoteContext();
if (!editor) {
editor = editorContext?.editor;
}
useEffect(() => {
if (!editor) {
throw new Error(
"'editor' is required, either from BlockNoteContext or as a function argument",
);
}
return editor.onChange(callback);
}, [callback, editor]);
}