mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
17 lines
456 B
TypeScript
17 lines
456 B
TypeScript
/**
|
|
* Combine refs to allow assignment to all passed refs
|
|
*/
|
|
export default function mergeRefs<T = any>(
|
|
refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined>
|
|
): React.RefCallback<T> {
|
|
return value => {
|
|
refs.forEach(ref => {
|
|
if (typeof ref === 'function') {
|
|
ref(value);
|
|
} else if (ref !== null && ref !== undefined) {
|
|
(ref as React.MutableRefObject<T | null>).current = value;
|
|
}
|
|
});
|
|
};
|
|
}
|