MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / useTrackFocus

Function useTrackFocus

console/src/store/focus.ts:15–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import { isPollingDisabled } from "~/util";
14
15export const useTrackFocus = () => {
16 const setValue = useSetAtom(isFocusedState);
17
18 const handleBlur = React.useCallback(() => {
19 setValue(false);
20 }, [setValue]);
21 const handleFocus = React.useCallback(() => {
22 setValue(true);
23 }, [setValue]);
24
25 React.useEffect(() => {
26 window.addEventListener("blur", handleBlur);
27 window.addEventListener("focus", handleFocus);
28 });
29};
30
31export const isFocusedState = atom<boolean>(document.hasFocus());
32

Callers 1

useAppInitializerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected