Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created May 28, 2017 03:02
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 ehzawad/cb916304521e315fd7eeab89c9cb378c to your computer and use it in GitHub Desktop.
Save ehzawad/cb916304521e315fd7eeab89c9cb378c to your computer and use it in GitHub Desktop.
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