Created
May 28, 2017 03:02
-
-
Save ehzawad/cb916304521e315fd7eeab89c9cb378c 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
class MyComponent extends React.Component { | |
constructor(props){ | |
super(props); | |
this.focus = this.focus.bind(this); | |
} | |
focus() { | |
// explicitly focus the text input using the raw DOM API | |
this.textInput.focus(); | |
} | |
render() { | |
return ( | |
<div> | |
<input type="text" ref={input => this.textInput = input} /> | |
<input type="button" value={"Focus the text"} onClick={this.focus} /> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<MyComponent />, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment