@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
26 lines (22 loc) • 598 B
JavaScript
/**
* MSKCC 2021, 2024
*/
import { useCallback } from '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 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);
};
export { useMergedRefs };