Appearance
useIsomorphicLayoutEffect
useLayoutEffect on the client, useEffect on the server
Demo
Usage
tsx
import { useIsomorphicLayoutEffect } from '@reause/shared'
import { useRef } from 'react'
const boxRef = useRef<HTMLDivElement>(null)
useIsomorphicLayoutEffect(() => {
// on the client this runs after the DOM is committed and before the browser
// paints — a real measurement, in the same frame
setWidth(boxRef.current?.getBoundingClientRect().width ?? 0)
}, [])Type Declarations
ts
export const useIsomorphicLayoutEffect