Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CowClicker = React.createClass({
- getInitialState: function() {
- return {
- clicks: 10,
- val:1 // this has been added by me
- };
- },
- onCowClick: function(evt) {
- this.setState({
- clicks: this.state.clicks + 1,
- val: this.state.val * this.state.clicks, // code part in question
- }
- });
- },
- render: function() {
- return (
- <div>
- <div>Clicks: {this.state.clicks}</div>
- <div>Val: {this.state.val}</div>
- <img
- src="http://s3.bypaulshen.com/buildwithreact/cow.png"
- onClick={this.onCowClick}
- className="cow"
- />
- <p>Click the cow</p>
- </div>
- );
- }
- });
- ReactDOM.render(
- <CowClicker />,
- document.getElementById('container')
- );
- onCowClick: function(evt) {
- this.setState({
- clicks: this.state.clicks + 1,
- alert(this.state.val),
- if(this.state.val > 1000000){
- val: 1,
- }else{
- val: this.state.val * this.state.clicks,
- }
- });
- },
Add Comment
Please, Sign In to add comment