Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / hooks / useCombinedRefs.ts
blob8a9223a9af00da0418901a52395d4fa5cd8f5534
1 import type { Ref } from 'react';
2 import { useCallback } from 'react';
4 const useCombinedRefs = <T extends any>(...refs: (Ref<T> | undefined)[]): Ref<T> =>
5     useCallback(
6         (element: T) =>
7             refs.forEach((ref) => {
8                 if (!ref) {
9                     return;
10                 }
12                 // Ref can have two types - a function or an object. We treat each case.
13                 if (typeof ref === 'function') {
14                     return ref(element);
15                 }
17                 // As per https://github.com/facebook/react/issues/13029
18                 // it should be fine to set current this way.
19                 (ref as any).current = element;
20             }),
21         refs
22     );
24 export default useCombinedRefs;