{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "compose-refs",
  "type": "registry:lib",
  "title": "composeRefs",
  "description": "Combines several React refs (callbacks or objects) into one ref callback, with React 19 cleanup support.",
  "author": "Design From Labs <https://labs.designfrom.com>",
  "categories": [
    "foundations"
  ],
  "docs": "Installed `composeRefs` in your lib folder. Pass every ref that must point at the same element.\n\nDocs and every variant: https://labs.designfrom.com/ui/compose-refs",
  "files": [
    {
      "path": "registry/compose-refs/compose-refs.ts",
      "type": "registry:lib",
      "content": "import type * as React from \"react\";\n\n/**\n * @dfl-header: v1, generated by labs.designfrom.com at build time\n * Item: compose-refs (composeRefs)\n * What: Combines several React refs (callbacks or objects) into one ref\n *    callback, with React 19 cleanup support.\n * Status: ready. License: MIT. Author: Design From Labs\n *    <https://labs.designfrom.com>\n * Source: https://github.com/Design-from-labs/labs @ 803b92c1a30e (examples/compose-refs)\n * Credits: S-003 React (MIT); S-004 shadcn/ui and its registry schema (MIT)\n * Install: npx shadcn@latest add https://labs.designfrom.com/r/compose-refs.json\n *   npx shadcn@latest add @designfrom/compose-refs\n *   npm i @designfrom/react, then import { composeRefs } from \"@designfrom/react/compose-refs\";\n * Docs: https://labs.designfrom.com/ui/compose-refs (index: https://labs.designfrom.com/llms.txt)\n */\n\n/**\n * One ref callback that keeps every given ref pointing at the same element.\n * Works with callback refs and ref objects, and returns a React 19 cleanup\n * that releases each of them.\n */\nexport function composeRefs<T>(\n  ...refs: Array<React.Ref<T> | undefined>\n): React.RefCallback<T> {\n  return (node) => {\n    const cleanups: Array<() => void> = [];\n    for (const ref of refs) {\n      if (typeof ref === \"function\") {\n        const cleanup = ref(node);\n        cleanups.push(\n          typeof cleanup === \"function\" ? cleanup : () => ref(null),\n        );\n      } else if (ref) {\n        ref.current = node;\n        cleanups.push(() => {\n          ref.current = null;\n        });\n      }\n    }\n    return () => {\n      for (const cleanup of cleanups) {\n        cleanup();\n      }\n    };\n  };\n}\n"
    }
  ],
  "meta": {
    "status": "ready",
    "license": "MIT",
    "author": "Design From Labs <https://labs.designfrom.com>",
    "source": {
      "repo": "https://github.com/Design-from-labs/labs",
      "commit": "803b92c1a30e0d513e1cb1ff5ca984b2a5f9b492",
      "path": "examples/compose-refs"
    },
    "credits": [
      "S-003",
      "S-004"
    ],
    "component": "compose-refs",
    "kind": "lib",
    "primitive": "none",
    "iconSet": "none",
    "page": "https://labs.designfrom.com/ui/compose-refs"
  }
}
