UNPKG

@orca-fe/hooks

Version:

React Hooks Collections

23 lines 666 B
import { useMemoizedFn } from 'ahooks'; export default function useMergedRefs(...refs) { return useMemoizedFn(instance => { refs.forEach(ref => { if (typeof ref === 'function') { ref(instance); } else if (ref != null && typeof ref === 'object') { // eslint-disable-next-line no-param-reassign ref.current = instance; } }); }); } useMergedRefs.mergeRefs = refs => instance => { refs.forEach(ref => { if (typeof ref === 'function') { ref(instance); } else if (ref != null && typeof ref === 'object') { // eslint-disable-next-line no-param-reassign ref.current = instance; } }); };