Created
January 2, 2018 13:55
-
-
Save emilyruby/8b1efe509cba2e50be7b58a8fa578394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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