1 line
1.3 KiB
Plaintext
1 line
1.3 KiB
Plaintext
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { useMemo } from \"react\"\n\nexport type ReactRef<T> = React.RefCallback<T> | React.MutableRefObject<T>\n\nexport function assignRef<T = any>(\n ref: ReactRef<T> | null | undefined,\n value: T,\n) {\n if (ref == null) return\n\n if (typeof ref === \"function\") {\n ref(value)\n return\n }\n\n try {\n ref.current = value\n } catch (error) {\n throw new Error(`Cannot assign value '${value}' to ref '${ref}'`)\n }\n}\n\nexport function mergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) {\n return (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node)\n })\n }\n}\n\nexport function useMergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => mergeRefs(...refs), refs)\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;AAIjB,SAAS,UACd,KACA,OACA;AACA,MAAI,OAAO;AAAM;AAEjB,MAAI,OAAO,QAAQ,YAAY;AAC7B,QAAI,KAAK;AACT;AAAA,EACF;AAEA,MAAI;AACF,QAAI,UAAU;AAAA,EAChB,SAAS,OAAP;AACA,UAAM,IAAI,MAAM,wBAAwB,kBAAkB,MAAM;AAAA,EAClE;AACF;AAEO,SAAS,aAAgB,MAA0C;AACxE,SAAO,CAAC,SAAmB;AACzB,SAAK,QAAQ,CAAC,QAAQ;AACpB,gBAAU,KAAK,IAAI;AAAA,IACrB,CAAC;AAAA,EACH;AACF;AAEO,SAAS,gBAAmB,MAA0C;AAE3E,SAAO,QAAQ,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI;AAC/C;","names":[]} |