Skip to content

useAdaptiveEffect

const useAdaptiveEffect: typeof useEffect

Defined in: hooks/dom/useAdaptiveEffect.ts:29

A hook that adapts to the environment: uses useLayoutEffect on the client side (when a DOM is available) and useEffect on the server side. This helps avoid React warnings such as "useLayoutEffect does nothing on the server".

See

Example

Just like useEffect, but it chooses the right hook depending on the environment.

tsx
useAdaptiveEffect(() => {
  // Your effect code here
}, [dependencies]);

Released under the MIT License.