0

I am wondering what the difference is, if any, between using this.setState({property: 1}) andthis.state.property = 1`

var App = React.createClass({

   getInitialState: function(){
      return({number: 0})
   },

   increaseNumber: function(){
      this.state.number += 1;
   },

   decreaseNumber: function(){
      this.setState({number: this.state.number - 1})
   }
})
  • @AndrewL. nice, so basically use `setState`. I can close this –  Sep 29 '16 at 21:01
  • http://stackoverflow.com/questions/35867038/what-the-difference-of-this-state-and-this-setstate-in-reactjs – erik-sn Sep 29 '16 at 21:02

1 Answers1

-1

If you do:

this.state = 1

it is a direct implementation but if you do it with the setter you can handle an exception or something like that befor you will initialize the value. In this case it doesn't matter.

I hope I could help you. :)