• 使用 16 版本后的 createRef()函数
  • class MyComponent extends React.Component<iProps, iState> {
  • constructor(props) {
  • super(props);
  • this.inputRef = React.createRef();
  • }
  • render() {
  • return <input type="text" ref={this.inputRef} />;
  • }
  • componentDidMount() {
  • this.inputRef.current.focus();
  • }
  • }

     
Posted on 2022-11-25 10:54  博客sl  阅读(35)  评论(0编辑  收藏  举报