{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "compose-refs",
  "title": "Compose Refs",
  "author": "VenusUI",
  "description": "Merge multiple React refs into a single callback ref.",
  "files": [
    {
      "path": "registry/default/lib/compose-refs.ts",
      "content": "import type * as React from \"react\"\n\ntype PossibleRef<T> = React.Ref<T> | undefined\n\nfunction setRef<T>(ref: PossibleRef<T>, value: T | null) {\n  if (typeof ref === \"function\") {\n    return ref(value)\n  }\n  if (ref) {\n    ref.current = value\n  }\n}\n\n/**\n * Combines several refs (callback refs or ref objects) into one callback ref.\n * Supports React 19 callback-ref cleanup functions.\n */\nexport function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {\n  return (node) => {\n    const cleanups = refs.map((ref) => setRef(ref, node))\n\n    return () => {\n      cleanups.forEach((cleanup, index) => {\n        if (typeof cleanup === \"function\") {\n          cleanup()\n        } else {\n          setRef(refs[index], null)\n        }\n      })\n    }\n  }\n}\n",
      "type": "registry:lib"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "utilities"
  ],
  "type": "registry:lib"
}