Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/slate-react/hooks/use-slate-static.tsx
1698 views
1
import { createContext, useContext } from "react";
2
3
import { ReactEditor } from "../plugin/react-editor";
4
5
/**
6
* A React context for sharing the editor object.
7
*/
8
9
export const EditorContext = createContext<ReactEditor | null>(null);
10
11
/**
12
* Get the current editor object from the React context.
13
*/
14
15
export const useSlateStatic = () => {
16
const editor = useContext(EditorContext);
17
18
if (!editor) {
19
throw new Error(
20
`The \`useSlateStatic\` hook must be used inside the <Slate> component's context.`
21
);
22
}
23
24
return editor;
25
};
26
27