美文网首页
React 笔记

React 笔记

作者: 不知道的是 | 来源:发表于2018-10-30 04:18 被阅读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

    相关文章

      网友评论

          本文标题:React 笔记

          本文链接:https://www.haomeiwen.com/subject/forwtqtx.html