Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created June 6, 2018 21:44
Show Gist options
  • Save gladchinda/08abb37b615bf8e5e3b2cb2d77b314a8 to your computer and use it in GitHub Desktop.
Save gladchinda/08abb37b615bf8e5e3b2cb2d77b314a8 to your computer and use it in GitHub Desktop.
class FormInput extends React.Component {
constructor(props) {
super(props);
this.textInput = React.createRef();
}
hasText() {
return this.textInput.current.value.length > 0;
}
selectInputText() {
this.textInput.current.select();
}
render() {
return (
<div>
{/* Creating a string ref named: textInput */}
<input type="text" ref={this.textInput} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment