I found this answer: ReactJS and autofocus
but I don't know how to convert this:
constructor(props) {
super(props);
this.myRef = React.createRef();
}
componentDidMount(){
this.myRef.current.focus();
}
<input type="text" ref={this.myRef} />
to react hooks version.
I tried doing this:
const myRef = () => {
React.createRef().current.focus();
}
<input type="text" ref={myRef} />
but got error:
TypeError: Cannot read property 'focus' of null