R: handleClick function
Alex Smith committed
Jun 27, 2015 at 12:13 UTC
67c70b86900bf5b2f3b76752e6417f09618b87aa
1 file changed
+5
-4
examples/basic-click-counter/Index.html
+5
-4
@@ -6,12 +6,13 @@
6
<script src="../../build/react.js"></script>
7
<script type="text/javascript">
8
var Counter = React.createClass({
9
- getInitialState: function() {
9
+ getInitialState: function () {
10
return { clickCount: 0 };
11
},
12
- handleClick: function() {
13
- var selfClickNumber = this.state.clickCount;
14
- this.setState({clickCount: ++selfClickNumber});
12
+ handleClick: function () {
13
+ this.setState(function(state) {
14
+ return {clickCount: state.clickCount + 1};
15
+ });
16
},
17
render: function () {
18
return React.DOM.h2({onClick: this.handleClick},