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-focused.ts
1698 views
1
import { createContext, useContext } from "react";
2
3
/**
4
* A React context for sharing the `focused` state of the editor.
5
* WARNING: For efficiency purposes it doesn't cause the component to update
6
* when the state changes.
7
*/
8
9
export const FocusedContext = createContext({ isFocused: false });
10
11
/**
12
* Get the current `focused` state of the editor.
13
*/
14
15
export const useFocused = (): boolean => {
16
return useContext(FocusedContext).isFocused;
17
};
18
19