React 笔记

2018-10-30  本文已影响0人  不知道的是

this.setState

handleClick() {
  this.setState(function (state) {
    return {
      // You should never mutate the state
      // count: state.count++,  // equal to -> count: this.state.count = this.state.count + 1
      count: state.count + 1 // recommend
    }
  }
}

let num = 1
let obj = {
  // 合法的操作
  count: num++, // equal to -> count: (num = num + 1)
}

obj // {count: 2}

https://stackoverflow.com/questions/39316376/how-to-use-the-increment-operator-in-react
https://reactjs.org/docs/react-component.html#setstate

上一篇 下一篇

猜你喜欢

热点阅读