react小技巧動態改變值的兩種方法

動態改變兩種值的方法

1.對象方式,簡單

this.setState({
            showWarning:!this.state.showWarning
        })

2.函數方式返回

    this.setState((state)=>{
            console.log(state);//就是state對象
          return{
            showWarning:!state.showWarning
          } 
            
        })
         // 2.函數方式返回,簡寫
          this.setState((state)=>({
              showWarning:!state.showWarning
          }))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章