Skip to content

Instantly share code, notes, and snippets.

@jackielii
Created July 11, 2015 13:06
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 jackielii/bad49686f530fdbf3662 to your computer and use it in GitHub Desktop.
Save jackielii/bad49686f530fdbf3662 to your computer and use it in GitHub Desktop.
mJLzEM
<div id="page"></div>
var App = React.createClass({
getInitialState: function() {
return {userInput: ''};
},
handleChange: function(e) {
this.setState({userInput: e.target.value});
},
clearAndFocusInput: function() {
this.setState({userInput: ''}); // Clear the input
// We wish to focus the <input /> now!
},
render: function() {
return (
<div>
<div onClick={this.clearAndFocusInput}>
Click to Focus and Reset
</div>
<input
value={this.state.userInput}
onChange={this.handleChange}
/>
</div>
);
}
});
React.render(<App />, document.getElementById("page"));
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js"></script>
<script src="http://codepen.io/chriscoyier/pen/yIgqi.js"></script>
body {
padding: 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment