@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
30 lines (24 loc) • 689 B
JavaScript
/**
* MSKCC 2021, 2024
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
/**
* Combine multiple refs into a single ref. This use useful when you have two
* refs from both `React.forwardRef` and `useRef` that you would like to add to
* the same node.
*/
const useMergedRefs = refs => {
return React.useCallback(node => {
refs.forEach(ref => {
if (typeof ref === 'function') {
ref(node);
} else if (ref !== null && ref !== undefined) {
ref.current = node;
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, refs);
};
exports.useMergedRefs = useMergedRefs;