Смотрите TypeScript ref.current изменений

  const refCallback = useCallback(<T extends HTMLElement>(node: T | null) => {
    if (!node) return
    // do your stuff
  }, [])
  
  // use it like:
  <div ref={(node) => refCallback(node)} />
T-DaMER