挂钩如何使输入标签自动聚焦?

时间:2020-06-17 10:51:06

标签: react-hooks

如何使输入标签在“ componentDidMount”之后自动获得焦点?

import React, { useRef, useEffect } from "react";

export default function App() {
  const refEl = useRef(null);
  useEffect(() => {
    refEl.current.focus();
  }, []);
  return (
    <div className="App">
      <input ref={refEl} />
    </div>
  );
}

0 个答案:

没有答案