mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
28 lines
662 B
JavaScript
28 lines
662 B
JavaScript
import React from 'react';
|
|
|
|
// basically Exclude<React.ClassAttributes<T>["ref"], string>
|
|
|
|
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]);
|
|
};
|
|
|
|
export { useComposedRef as default };
|