Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created December 13, 2013 21:41
Show Gist options
  • Save swannodette/7951844 to your computer and use it in GitHub Desktop.
Save swannodette/7951844 to your computer and use it in GitHub Desktop.
var Counter = React.createClass({
getInitialState: function() {
window.aCounter = this;
return {
count: 0
};
},
add: function() {
this.setState({count: this.state.count+1});
},
subtract: function() {
this.setState({count: this.state.count-1});
},
render: function() {
return (
React.DOM.div({
children: [
React.DOM.label({children: this.state.count}),
React.DOM.button({onClick: this.add, children: "+"}),
React.DOM.button({onClick: this.subtract, children: "-"})
]
})
);
}
});
React.renderComponent(
React.DOM.div({
children: [
React.DOM.h1({children: "A Counting Widget!"}),
Counter()
]
}),
document.getElementById('counters')
);
var s = new Date();
for(var i = 0; i < 10000; i++) {
aCounter.add();
}
console.log((new Date())-s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment