Skip to content

Instantly share code, notes, and snippets.

@heyjohnmurray
Last active November 19, 2015 21:44
Show Gist options
  • Save heyjohnmurray/9fab8b1f844d87d2e7e9 to your computer and use it in GitHub Desktop.
Save heyjohnmurray/9fab8b1f844d87d2e7e9 to your computer and use it in GitHub Desktop.
this is how you can update getInitialState in your app.
var App = React.createClass({
getInitialState: function() {
return {
text: 'this is initial state text',
};
},
// update is a custom function we've created
update: function(e) {
// this.setState is the key to update text in this example
this.setState({text: e.target.value});
},
render: function() {
return (
<div>
<input type='text' onChange={this.update} />
<h1>{this.state.text}</h1>
</div>
);
},
});
@heyjohnmurray
Copy link
Author

React acted weird about some syntax stuff. Most notably, it didn't like that the input tag had more standard HTML5 simple closing tag. It expected ' /> ' instead.

Looks like tag closing rules from here also apply to HTML tags, not just components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment