MCPcopy Create free account
hub / github.com/msgbyte/tailchat / useDataReady

Function useDataReady

client/shared/hooks/useDataReady.ts:7–27  ·  view source on GitHub ↗
(
  validator: () => boolean,
  cb: () => void,
  deps?: DependencyList
)

Source from the content-addressed store, hash-verified

5 * Call once on data ready(validator return true)
6 */
7export function useDataReady(
8 validator: () => boolean,
9 cb: () => void,
10 deps?: DependencyList
11) {
12 const isReadyRef = useRef(false);
13
14 const _validator = useEvent(validator);
15 const _callback = useEvent(cb);
16
17 useLayoutEffect(() => {
18 if (isReadyRef.current) {
19 return;
20 }
21
22 if (_validator() === true) {
23 _callback();
24 isReadyRef.current = true;
25 }
26 }, deps);
27}

Callers 1

useInjectTianjiScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected