Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.