Loading...
Please waitLoading...
Please waitCustom hook that uses either useLayoutEffect or useEffect based on the environment (client-side or server-side).
pnpm dlx uselab@latest add use-isomorphic-layout-effect
import { useIsomorphicLayoutEffect } from "@/hooks/isomorphic-layout-effect"
export function Component() {
useIsomorphicLayoutEffect(() => {
console.log(
"In the browser, I'm an `useLayoutEffect`, but in SSR, I'm an `useEffect`."
)
}, [])
return <p>Hello, world</p>
}| Name | Type | Description | Default Value | Optional |
|---|---|---|---|---|
effect | EffectCallback | The effect function to be executed. | - | No |
deps | DependencyList | The dependencies of the effect. | undefined | Yes |
| Name | Type | Description |
|---|---|---|
Function | void | - |