{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-retained",
  "title": "useRetained",
  "description": "Keeps the last non-null value while a dialog animates closed.",
  "files": [
    {
      "path": "registry/khaeli/hooks/use-retained.ts",
      "content": "import { useState } from \"react\"\n\n/**\n * Keeps the last non-null value while a dialog animates closed.\n * `open` drives the dialog; `value` is what it renders; call\n * `onOpenChangeComplete` from the dialog so the copy clears once the exit\n * has finished.\n */\nexport function useRetained<T>(current: T | null) {\n  const [retained, setRetained] = useState<T | null>(current)\n  if (current !== null && current !== retained) setRetained(current)\n  return {\n    open: current !== null,\n    value: current ?? retained,\n    onOpenChangeComplete: (open: boolean) => {\n      if (!open) setRetained(null)\n    },\n  }\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}