source: imaps-frontend/node_modules/react-tiles-dnd/esm/utils/useComposedRef.js.map

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
Line 
1{"version":3,"file":"useComposedRef.js","sources":["../../../src/utils/useComposedRef.ts"],"sourcesContent":["import { Ref, useCallback } from 'react';\n\n/**\n * returns a function that composes multiple refs together.\n * This can be very useful when you have more hooks that create a ref\n * that shall be given to a DOM component, but the component only accepts\n * one ref!\n *\n * Example:\n *\n * ```\n * import { useMeasure } from 'react-use';\n * import { useDrop } from 'react-dnd';\n *\n * const MyComponent = () => {\n * const [measureRef, measure] = useMeasure<HTMLDivElement>();\n * const [_, dropRef] = useDrop({accept: 'TILE'});\n * const reactRef = useRef<HTMLDivElement>(null);\n *\n * const composedRef = useComposeRef(measureRef, dropRef, reactRef)\n *\n * return <div ref={composedRef}/>\n * }\n * ```\n * @param refs a list of refs that shall be composed together\n * @returns a new ref that shall be given to the component\n */\nexport const useComposeRef = <T extends HTMLElement>(...refs: Ref<T>[]) => {\n return useCallback((el: T | null) => {\n refs.forEach(ref => {\n if (ref) {\n if (typeof ref === 'function') ref(el);\n //@ts-ignore\n else ref.current = el;\n }\n });\n }, refs);\n};\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;IAyBa,aAAa,GAAG;IAAwB,cAAiB;SAAjB,UAAiB,EAAjB,qBAAiB,EAAjB,IAAiB;QAAjB,yBAAiB;;IACpE,OAAO,WAAW,CAAC,UAAC,EAAY;QAC9B,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;YACd,IAAI,GAAG,EAAE;gBACP,IAAI,OAAO,GAAG,KAAK,UAAU;oBAAE,GAAG,CAAC,EAAE,CAAC,CAAC;;;oBAElC,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;aACvB;SACF,CAAC,CAAC;KACJ,EAAE,IAAI,CAAC,CAAC;AACX;;;;"}
Note: See TracBrowser for help on using the repository browser.