This hook fixes this problem by switching between useEffect and useLayoutEffect following the execution environment.
This hook fixes the problem of useLayoutEffect not having any effect on SSR by switching between useEffect and useLayoutEffect following the execution environment.
import { useIsomorphicLayoutEffect } from "usehooks-ts";export default function Component() {useIsomorphicLayoutEffect(() => {console.log("In the browser, I'm an `useLayoutEffect`, but in SSR, I'm an `useEffect`.");}, []);return <p>Hello, world</p>;}