useAdaptiveEffect()
useAdaptiveEffect(
effect
,deps
?):void
Defined in: src/hooks/dom/useAdaptiveEffect.ts:24
A hook that adapts to the environment: uses useLayoutEffect
on the client side and useEffect
on the server side. This ensures compatibility with both SSR and CSR environments.
Inspired by the implementation from usehooks-ts.
Parameters
effect
EffectCallback
Imperative function that can return a cleanup function
deps?
DependencyList
If present, effect will only activate if the values in the list change.
Returns
void
See
- https://github.com/juliencrn/usehooks-ts Original implementation
- https://react.dev/reference/react/useEffect React useEffect documentation
- https://react.dev/reference/react/useLayoutEffect React useLayoutEffect documentation
Example
Just like useEffect
, but it chooses the right hook depending on the environment.
tsx
useAdaptiveEffect(() => {
// Your effect code here
}, [dependencies]);
Version
16.8.0