[React Typescript] useRef with HTML Elements

React set the ref to null in runtime. It is a limitation now for react.

import { useRef } from 'react';

export const Component = () => {
  const ref = useRef<HTMLDivElement>(null);
  return <div ref={ref} />;
};

 

posted @ 2023-05-24 15:11  Zhentiw  阅读(14)  评论(0编辑  收藏  举报