Skip to content

Instantly share code, notes, and snippets.

@mattdell
Created October 1, 2015 11:50
Show Gist options
  • Save mattdell/642cb1980c2526359afa to your computer and use it in GitHub Desktop.
Save mattdell/642cb1980c2526359afa to your computer and use it in GitHub Desktop.
React Demo 4 - State
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://fb.me/react-0.13.3.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.25.2/react-bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div id="content"></div>
</div>
<script type="text/jsx">
var HelloWorld = React.createClass({
getInitialState: function() {
return {
count: 0
}
},
_increment: function() {
this.setState({
count: this.state.count + 1
});
},
render: function() {
return (
<div>
<h1>{this.state.count}</h1>
<button onClick={this._increment}>Click me!</button>
</div>
);
}
});
React.render(<HelloWorld />, document.getElementById('content'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment