Use Keyed Layout Effect
retab-ui/use-keyed-layout-effectFreeHook
A key-driven layout-timed effect hook for DOM measurement and scroll/focus lifecycles.
Install it
npx shadcn@latest add https://ui.retab.com/r/use-keyed-layout-effect.jsonSource
1"use client";23import { useEffect, useLayoutEffect } from "react";45const useIsomorphicLayoutEffect =6 typeof window === "undefined" ? useEffect : useLayoutEffect;78/**9 * Layout-timed variant for DOM measurement/scroll/focus lifecycles that must10 * run before paint. Prefer `use-keyed-mount-effect` for ordinary post-commit11 * effects.12 */13export function useKeyedLayoutEffect(14 key: string | null,15 effect: () => void | (() => void),16) {17 useIsomorphicLayoutEffect(() => {18 if (key === null) return;19 return effect();20 // The effect closure is intentionally captured at each key change.21 }, [key]);22}
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Use Keyed Mount Effectuse-keyed-mount-effect | retab-ui | Hooks | Free | no deps | |
| Use Mobileuse-mobile | retab-ui | Hooks | Free | no deps | |
| Use Mount Effectuse-mount-effect | retab-ui | Hooks | Free | no deps |
