I'm trying to use refs is ReactJs, to focus the textbox from a button click.
But I get the following error message:-
bundle.js:114 Uncaught TypeError: Cannot read property 'focus' of undefined
Source Code
class FocusText extends Component{
handleClick(){
this.refs.myTextInput.focus();
}
render(){
return(
<div>
<input type="text" ref="myTextInput"/>
<input type="button"
value="Focus the text input"
onClick={this.handleClick.bind(this)}/>
</div>
);
}
}
React.render(<FocusText/>, document.getElementById('root'));