Use Keyed Mount Effect
retab-ui/use-keyed-mount-effectFreeHook
A key-driven post-commit effect hook for library internals.
Install it
npx shadcn@latest add https://ui.retab.com/r/use-keyed-mount-effect.jsonSource
1"use client";23import { useEffect } from "react";45/**6 * Hook variant of <KeyedRunner>. Runs `effect` each time `key` changes7 * (including the first mount). Returned cleanup runs before the next run8 * and on unmount. No-ops when `key` is `null`.9 *10 * This exists ONLY for library hooks whose internals need reactive11 * post-commit side effects. Prefer <KeyedRunner> in component code.12 */13export function useKeyedMountEffect(14 key: string | null,15 effect: () => void | (() => void),16) {17 // eslint-disable-next-line no-restricted-syntax18 useEffect(() => {19 if (key === null) return;20 return effect();21 // The effect closure is intentionally captured at each key change;22 // eslint's exhaustive-deps would demand we include `effect`, but23 // the semantics are key-driven, not effect-identity-driven.2425 }, [key]);26}
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Use Keyed Layout Effectuse-keyed-layout-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 |
