var Hello = React.createClass({
mixins: [React.addons.PureRenderMixin],
renderCount: 0,
getInitialState: function() {
return { data: Immutable.Map({count: {value: 0}})};
},
countUp: function() {
var value = this.state.data.update('count',function(v){
var val = v.value + 1;
return { value: val };
});
return this.setState({data: value});
},
fourceUpdate: function() {
this.forceUpdate();
},
render: function() {
this.renderCount += 1;
var data = this.state.data.get('count');
return (
<div>
<div>Count: {data.value}</div>
<div>Render: {this.renderCount}</div>
<button onClick={this.countUp}>Count Up</button>
<button onClick={this.fourceUpdate}>Forde Update</button>
</div>
);
}
});
React.render(<Hello />, document.body);
External resources loaded into this fiddle:
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>