/** * @typedef PossibleRef * @type {React.Ref | undefined;} * * @typedef setRef * @type {(ref: PossibleRef, value: T) => React.RefCallback} */ /** * @type {setRef} */ const setRef = (ref, value) => { if (typeof ref === 'function') { ref(value); } else if (ref !== null && ref !== undefined) { ref.current = value; } }; /** * A utility to compose multiple refs together * Accepts callback refs and RefObject(s) * * @type {(...refs: PossibleRef[]) => (node: T) => void} */ export const composeRefs = (...refs) => { return (node) => refs.forEach((ref) => setRef(ref, node)); };