@linzjs/step-ag-grid
Version:
[](https://github.com/semantic-release/semantic-release) > Reusable [ag-grid](https://www.ag-grid.com/) component for LINZ / Toitū te whenua.
25 lines (21 loc) • 714 B
text/typescript
import { ForwardedRef, LegacyRef, useMemo } from 'react';
// Adapted from material-ui
// https://github.com/mui-org/material-ui/blob/f996027d00e7e4bff3fc040786c1706f9c6c3f82/packages/material-ui-utils/src/useForkRef.ts
const setRef = <T>(ref: ForwardedRef<T> | undefined, instance: T | null) => {
if (typeof ref === 'function') {
ref(instance);
} else if (ref) {
ref.current = instance;
}
};
export const useCombinedRef = <Instance>(
refA: ForwardedRef<Instance> | undefined,
refB: ForwardedRef<Instance> | undefined,
): LegacyRef<Instance> => {
return useMemo(() => {
return (instance: any) => {
setRef(refA, instance);
setRef(refB, instance);
};
}, [refA, refB]);
};