Skip to content

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

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

See

https://react.dev/reference/react/useEffect

Released under the MIT License.