Skip to content

Instantly share code, notes, and snippets.

@emilyruby
Created January 2, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilyruby/8b1efe509cba2e50be7b58a8fa578394 to your computer and use it in GitHub Desktop.
Save emilyruby/8b1efe509cba2e50be7b58a8fa578394 to your computer and use it in GitHub Desktop.
class RefExample extends React.Component {
constructor (props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
this.textInput.focus()
}
render () {
return (
<div>
<input ref={(thisInput) => {this.textInput = thisInput}} type="text" />
<input
type="button"
value="Keep focus on text input."
onClick={this.handleClick}
/>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment