useLazyEffect
useLazyEffect is useEffect without the first run. The callback runs only when deps change after mount — the
hook form of componentDidUpdate.Hooks
Signature
useLazyEffect(cb: () => any, deps: any[]): void;
Name | Type | Description |
|---|---|---|
cb | () => any | Runs after a deps change, never on the first mount. |
deps | any[] | Dependency list, with the same semantics as useEffect. |
returns | void |
Scrolls sideways inside the table. The page does not.
Example
import { useLazyEffect } from '@apollion-dsi/core/hooks';
function Results({ query }: { query: string }) {
useLazyEffect(() => {
fetchResults(query);
}, [query]);
return null;
}Pitfalls
- A cleanup function returned by
cbis ignored. Do not use it for subscriptions that need teardown. - In development Strict Mode React re-runs effects after mount, so the callback also runs once on mount there.
- Lint cannot check
depsfor this hook; list them carefully.