Я нашел этот ответ: ReactJS и автофокус
но я не знаю, как это преобразовать:
constructor(props) {
super(props);
this.myRef = React.createRef();
}
componentDidMount(){
this.myRef.current.focus();
}
<input type="text" ref={this.myRef} />
реагировать на версию хуков.
Я пробовал это сделать:
const myRef = () => {
React.createRef().current.focus();
}
<input type="text" ref={myRef} />
но получил ошибку:
TypeError: Cannot read property 'focus' of null