| // src/compose-refs.tsx | |
| import * as React from "react"; | |
| function setRef(ref, value) { | |
| if (typeof ref === "function") { | |
| return ref(value); | |
| } else if (ref !== null && ref !== void 0) { | |
| ref.current = value; | |
| } | |
| } | |
| function composeRefs(...refs) { | |
| return (node) => { | |
| let hasCleanup = false; | |
| const cleanups = refs.map((ref) => { | |
| const cleanup = setRef(ref, node); | |
| if (!hasCleanup && typeof cleanup == "function") { | |
| hasCleanup = true; | |
| } | |
| return cleanup; | |
| }); | |
| if (hasCleanup) { | |
| return () => { | |
| for (let i = 0; i < cleanups.length; i++) { | |
| const cleanup = cleanups[i]; | |
| if (typeof cleanup == "function") { | |
| cleanup(); | |
| } else { | |
| setRef(refs[i], null); | |
| } | |
| } | |
| }; | |
| } | |
| }; | |
| } | |
| function useComposedRefs(...refs) { | |
| return React.useCallback(composeRefs(...refs), refs); | |
| } | |
| export { | |
| composeRefs, | |
| useComposedRefs | |
| }; | |
| //# sourceMappingURL=index.mjs.map | |
Xet Storage Details
- Size:
- 982 Bytes
- Xet hash:
- 3f5081bd1ae593b21ae7f04308e80404ea9f1e1c90018546c34a6409f4795ec9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.