Last active
November 19, 2015 21:44
-
-
Save heyjohnmurray/9fab8b1f844d87d2e7e9 to your computer and use it in GitHub Desktop.
this is how you can update getInitialState in your app.
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
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> | |
); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.