'use client'; import * as React from 'react'; /** * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that * updates all provided refs * @param refs - Refs to collectively update with one ref value. * @returns A function with an attached "current" prop, so that it can be treated like a RefObject. */ // LegacyRef is actually not supported, but in React v18 types this is leaking directly from forwardRef component declaration export function useMergedRefs(...refs) { 'use no memo'; const mergedCallback = React.useCallback((value)=>{ // Update the "current" prop hanging on the function. mergedCallback.current = value; for (const ref of refs){ if (typeof ref === 'string' && process.env.NODE_ENV !== 'production') { // eslint-disable-next-line no-console console.error(`@fluentui/react-utilities [useMergedRefs]: This hook does not support the usage of string refs. Please use React.useRef instead. For more info on 'React.useRef', see https://react.dev/reference/react/useRef. For more info on string refs, see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-string-refs.`); } if (typeof ref === 'function') { ref(value); } else if (ref) { ref.current = value; } } }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive [ ...refs ]); return mergedCallback; }