( validator: () => boolean, cb: () => void, deps?: DependencyList )
| 5 | * Call once on data ready(validator return true) |
| 6 | */ |
| 7 | export 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 | } |
no outgoing calls
no test coverage detected