setState的两种使用方法
1.对象式的setState
(1)不带回调函数
this.setState({ aa:1 })
(2)带回调函数(一般不传)
this.setState({ aa:1},()=>{
console.log('是setState更新完,页面render完,再执行这个函数')
})
2.函数式的setState
this.setState((state, props) => {
console.log(state, props)
return {count: state.count + 100}
})
可简写
this.setState(state=> ({count: state.count + 100 }) )