framer-motion
Version:
A simple and powerful JavaScript animation library
22 lines (20 loc) • 654 B
JavaScript
/**
* A callback ref that sets our own `ref` and an external one, a callback
* ref or ref object. A callback ref's cleanup is called instead of the ref
* with null, so it's returned wrapped to clear our own ref too.
*/
const mergeRefs = (ref, externalRef) => (value) => {
ref.current = value;
const cleanup = typeof externalRef === "function"
? externalRef(value)
: externalRef &&
(externalRef.current = value);
if (typeof cleanup === "function") {
return () => {
ref.current = null;
cleanup();
};
}
};
export { mergeRefs };
//# sourceMappingURL=merge-refs.mjs.map