Created helper function to convert mutable refs from useRef into element refs for the ref prop

This commit is contained in:
Alejandro Celaya
2022-06-06 20:46:51 +02:00
parent b450e4093e
commit 7669254a0c
6 changed files with 18 additions and 21 deletions

View File

@@ -0,0 +1,5 @@
import { MutableRefObject, Ref } from 'react';
export const mutableRefToElementRef = <T>(ref: MutableRefObject<T | undefined>): Ref<T> => (el) => {
ref.current = el ?? undefined; // eslint-disable-line no-param-reassign
};