Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/use-change.ts
1691 views
1
/*
2
A hook that can be used so that each mounted and rendered component updates
3
itself in some way on every change to the document. Obviously this is potentially
4
very inefficient, so should be used with care or for debugging/prototyping work only.
5
*/
6
7
import type { SlateEditor } from "./types";
8
import { createContext, useContext } from "react";
9
10
export const ChangeContext = createContext<{
11
change: number;
12
editor: SlateEditor | null;
13
setEditor?: (editor: null | any) => void;
14
}>({ change: 0, editor: null });
15
export const useChange = () => useContext(ChangeContext);
16
17