如何使输入标签在“ 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>
);
}