我的要求是更新 componentWillReceiveProps 的 map 函数中的状态值。
在控制台日志中,我得到的只是 1,但 sub.subscribed 包含 0 和 1
控制台窗口参考:http: //prntscr.com/jqifiz
constructor(props) {
super(props);
this.state = {
regionAll: [],
};
}
componentWillReceiveProps(nextProps){
if(nextProps.apiData !== false ){
nextProps.apiData.data.datacenter.category.map((sub)=> {
console.log(sub.subscribed,'sub.subscribed');
this.setState({
regionAll: [
...this.state.regionAll,
sub.subscribed
]
},()=>{
console.log(this.state.regionAll,'sub');
})
})
}
这是在reactjs中更新状态的正确方法吗?