Skip to content

Instantly share code, notes, and snippets.

@Will-Sommers
Created February 18, 2016 01:36
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 Will-Sommers/40e955c382a569eb84b3 to your computer and use it in GitHub Desktop.
Save Will-Sommers/40e955c382a569eb84b3 to your computer and use it in GitHub Desktop.
react intro jsx
var Hello = React.createClass({
getInitialState: function() {
return {
message: "hi hi hi",
color: "red"
}
},
updateMessage: function(event) {
var newValue = event.target.value;
var updateHash = { message: newValue };
if (event.target.value.length > 5) {
updateHash.color = "blue";
} else {
updateHash.color = "red";
}
this.setState(updateHash);
},
render: function() {
return (
<div>
<h1>Hi ya'll</h1>
<input onInput={this.updateMessage} placeholder="Add a message!" />
<div style={{color: this.state.color, marginTop: "20px"}}>{this.state.message}</div>
</div>
);
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment