Skip to content

useIsomorphicLayoutEffect

SSR-safe useLayoutEffect alias.

A drop-in replacement for useLayoutEffect that falls back to useEffect on the server. Eliminates the SSR "useLayoutEffect does nothing" warning without branching at each call site.

Installation

pnpm dlx shadcn@latest add @frontal-labs/use-isomorphic-layout-effect

Usage

import { useIsomorphicLayoutEffect } from "@/hooks/use-isomorphic-layout-effect";
 
function Measured() {
  useIsomorphicLayoutEffect(() => {
    // DOM measurement safe to run in browser, no-op warning on server
  }, []);
 
  return <div />;
}

API

const useIsomorphicLayoutEffect: typeof useEffect;

Resolves to useLayoutEffect in the browser and useEffect when window is undefined. Same signature as both.