This commit is contained in:
2026-04-25 16:36:34 +08:00
commit db90e7579b
1876 changed files with 189777 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { DependencyList, useLayoutEffect, useRef } from 'react';
import { useEvent } from './useEvent';
/**
* Call once on data ready(validator return true)
*/
export function useDataReady(
validator: () => boolean,
cb: () => void,
deps?: DependencyList
) {
const isReadyRef = useRef(false);
const _validator = useEvent(validator);
const _callback = useEvent(cb);
useLayoutEffect(() => {
if (isReadyRef.current) {
return;
}
if (_validator() === true) {
_callback();
isReadyRef.current = true;
}
}, deps);
}