Files
twenty/packages/twenty-front/src/utils/combineRefs.ts
T
Félix Malfait 464a480043 Continue ESLINT9 Migration (#13795)
Might already fix #13793
2025-08-10 23:25:58 +02:00

16 lines
460 B
TypeScript

import { isFunction } from '@sniptt/guards';
import { type MutableRefObject, type Ref } from 'react';
import { isDefined } from 'twenty-shared/utils';
export const combineRefs = <T>(...refs: (Ref<T> | undefined)[]) => {
return (node: T) => {
for (const ref of refs) {
if (isFunction(ref)) {
ref(node);
} else if (isDefined(ref) && 'current' in ref) {
(ref as MutableRefObject<T | null>).current = node;
}
}
};
};