I tried to make input focused when component render. I copied from React doc example https://reactjs.org/docs/refs-and-the-dom.html
My version:
class CreateTask extends React.Component {
constructor(props){
super(props);
}
componentDidMount(){
this.textInput.focus();
}
render (){
if (this.props.visibility == true){
return(
<div className="new_task_form">
<h2>New task</h2>
<input type="text" ref={(input) => { this.textInput = input; }} onChange={this.props.handleEdit} value={this.props.messageValue} />
<div>);
}
}
I am always getting the same error message - TypeError: this.textInput is undefined. Did anyone came across the same issue? Any help is much appreciated!