{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "compose-refs",
  "title": "composeRefs",
  "description": "Combines several React refs into one callback ref, with React 19 ref cleanup support.",
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "lib/compose-refs.ts",
      "content": "import type { Ref, RefCallback } from \"react\"\n\n/**\n * Combines several refs (callback or object) into one callback ref.\n * On detach, object refs are cleared, callback refs that returned a cleanup\n * have it called, and the others receive `null` (React 19 semantics).\n */\nexport function composeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {\n  return (node) => {\n    const detach: (() => void)[] = []\n    for (const ref of refs) {\n      if (typeof ref === \"function\") {\n        const cleanup = ref(node)\n        detach.push(typeof cleanup === \"function\" ? cleanup : () => ref(null))\n      } else if (ref) {\n        ref.current = node\n        detach.push(() => {\n          ref.current = null\n        })\n      }\n    }\n    return () => {\n      for (const fn of detach) fn()\n    }\n  }\n}\n",
      "type": "registry:lib"
    }
  ],
  "meta": {
    "tier": "free",
    "collection": "interface",
    "needsImage": false,
    "addedAt": "2026-10-12",
    "tags": [
      "refs",
      "utility"
    ],
    "tech": [],
    "presets": [],
    "keyboard": [],
    "heavy": false
  },
  "categories": [
    "internal"
  ],
  "type": "registry:lib"
}