Guest User

Untitled

a guest
Nov 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. var CowClicker = React.createClass({
  2. getInitialState: function() {
  3. return {
  4. clicks: 10,
  5. val:1 // this has been added by me
  6. };
  7. },
  8.  
  9. onCowClick: function(evt) {
  10. this.setState({
  11. clicks: this.state.clicks + 1,
  12. val: this.state.val * this.state.clicks, // code part in question
  13. }
  14. });
  15. },
  16.  
  17. render: function() {
  18. return (
  19. <div>
  20. <div>Clicks: {this.state.clicks}</div>
  21. <div>Val: {this.state.val}</div>
  22. <img
  23. src="http://s3.bypaulshen.com/buildwithreact/cow.png"
  24. onClick={this.onCowClick}
  25. className="cow"
  26. />
  27. <p>Click the cow</p>
  28. </div>
  29. );
  30. }
  31. });
  32.  
  33. ReactDOM.render(
  34. <CowClicker />,
  35. document.getElementById('container')
  36. );
  37.  
  38. onCowClick: function(evt) {
  39. this.setState({
  40. clicks: this.state.clicks + 1,
  41. alert(this.state.val),
  42. if(this.state.val > 1000000){
  43. val: 1,
  44. }else{
  45. val: this.state.val * this.state.clicks,
  46. }
  47. });
  48. },
Add Comment
Please, Sign In to add comment