import * as React from 'react' ; import { useRef } from 'react' ; export default function useRefs < RefType > ( ) { const cacheRefs = useRef ( new Map < React . Key , React . RefObject < RefType > > ( ) ) ; function getRef ( key ) { if ( ! cacheRefs . current . has ( key ) ) { cacheRefs . current . set ( key , React . createRef < RefType > ( ) ) ; } return cacheRefs . current . get ( key ) ; } function removeRef ( key ) { cacheRefs . current . delete ( key ) ; } return [ getRef , removeRef ] ; }