Skip to main content

useIsomorphicLayoutEffect

The useIsomorphicLayoutEffect provides a hook to ensure that it runs synchronously even in server-side rendering environments.

Use useLayoutEffect in the client environment and useEffect in the server environment.


Interface

const useIsomorphicLayoutEffect: (
effect: React.EffectCallback,
deps?: React.DependencyList | undefined
) => void;

Usage

import { useIsomorphicLayoutEffect } from '@devgrace/react';

const Example = () => {
useIsomorphicLayoutEffect(() => {
console.log(
"This is useLayoutEffect in the client environment and useEffect in the server environment.",
)
}, []);

return <div>{/* ... */}</div>;
};