Improved types on element ref objects and their usage

This commit is contained in:
Alejandro Celaya
2023-01-10 20:04:47 +01:00
parent 98e2e57bb2
commit 487c832f5b
7 changed files with 26 additions and 31 deletions

View File

@@ -1,5 +0,0 @@
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
};

View File

@@ -1,4 +1,4 @@
import { useState, useRef, EffectCallback, DependencyList, useEffect } from 'react';
import { DependencyList, EffectCallback, useEffect, useRef, useState } from 'react';
import { useSwipeable as useReactSwipeable } from 'react-swipeable';
import { useLocation, useNavigate } from 'react-router-dom';
import { v4 as uuid } from 'uuid';
@@ -91,3 +91,5 @@ export const useDomId = (): string => {
const { current: id } = useRef(`dom-${uuid()}`);
return id;
};
export const useElementRef = <T>() => useRef<T | null>(null);