Files
coopgo/node_modules/use-composed-ref/dist/use-composed-ref.cjs.js
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

35 lines
682 B
JavaScript

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var updateRef = function updateRef(ref, value) {
if (typeof ref === 'function') {
ref(value);
return;
}
ref.current = value;
};
var useComposedRef = function useComposedRef(libRef, userRef) {
var prevUserRef = React.useRef();
return React.useCallback(function (instance) {
libRef.current = instance;
if (prevUserRef.current) {
updateRef(prevUserRef.current, null);
}
prevUserRef.current = userRef;
if (!userRef) {
return;
}
updateRef(userRef, instance);
}, [userRef]);
};
exports.default = useComposedRef;