MCPcopy
hub / github.com/udecode/plate / useIsVisible

Function useIsVisible

packages/toggle/src/react/toggleIndexAtom.ts:57–73  ·  view source on GitHub ↗
(elementId: string)

Source from the content-addressed store, hash-verified

55// In order minimize re-renders, we subscribe to both separately, but only re-render unnecessarily when opening or closing a toggle,
56// which is less frequent than changing the editor's children.
57export const useIsVisible = (elementId: string) => {
58 const openIds = usePluginOption(TogglePlugin, 'openIds')!;
59 const isVisibleAtom = useMemo(
60 () =>
61 atom((get) => {
62 const toggleIndex = get(toggleIndexAtom);
63 const enclosedInToggleIds = toggleIndex.get(elementId) || [];
64
65 return enclosedInToggleIds.every((enclosedId) =>
66 openIds.has(enclosedId)
67 );
68 }),
69 [elementId, openIds]
70 );
71
72 return useStoreAtomValue(usePlateStore(), isVisibleAtom);
73};
74
75export const toggleIndexAtom: Atom<Map<string, string[]>> = atom((get) =>
76 buildToggleIndex(get(editorAtom).editor.children as TIndentElement[])

Callers 1

ToggleAboveNodesFunction · 0.90

Calls 4

usePluginOptionFunction · 0.90
usePlateStoreFunction · 0.90
getFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…