forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseCreateBlockNote.tsx
More file actions
36 lines (35 loc) · 1.01 KB
/
Copy pathuseCreateBlockNote.tsx
File metadata and controls
36 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
BlockNoteEditor,
BlockNoteEditorOptions,
CustomBlockNoteSchema,
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema,
} from "@blocknote/core";
import { DependencyList, useMemo } from "react";
/**
* Hook to instantiate a BlockNote Editor instance in React
*/
export const useCreateBlockNote = <
Options extends Partial<BlockNoteEditorOptions<any, any, any>> | undefined,
>(
options: Options = {} as Options,
deps: DependencyList = [],
): Options extends {
schema: CustomBlockNoteSchema<infer BSchema, infer ISchema, infer SSchema>;
}
? BlockNoteEditor<BSchema, ISchema, SSchema>
: BlockNoteEditor<
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema
> => {
return useMemo(() => {
const editor = BlockNoteEditor.create(options) as any;
if (window) {
// for testing / dev purposes
(window as any).ProseMirror = editor._tiptapEditor;
}
return editor;
}, deps); //eslint-disable-line react-hooks/exhaustive-deps
};