【发布时间】:2017-03-16 12:49:29
【问题描述】:
我收到此错误在路径中的调度之间检测到状态突变
我在 componentWillReceiveProps 中使用了 setState :
this.setState({ checkboxes: nextProps.data.my_details});
在渲染函数中,我生成了动态复选框,并根据我得到的值显示复选框是否选中。见下面的代码:
renderSubCategory(data, indexParent){
let indexParent1 = indexParent;
const {checkboxes} = this.state;
return checkboxes[indexParent1].sub_categories.map((data1, index1) => {
return(
<View key={index1}>
<View style={{ flex: 1, flexDirection: 'column' }}>
<CheckBox
label={data1.name}
labelStyle={{fontSize:14}}
size={25}
color='#17bb8f'
checked={data1.status_code === 0 ? false : true}
onPress={(checked)=>this.handlePressCheckedBox(index1, checked, indexParent1)}
/>
</View>
</View>
)
})
}
现在复选框的 onPress 函数我正在更改复选框的状态并出现突变错误。
handlePressCheckedBox = (index,checked, indexParent1) => {
const {checkboxes} = this.state;
if(checkboxes[indexParent1].sub_categories[index].status_code === 0){
checkboxes[indexParent1].sub_categories[index].status_code = 1;
}else{
checkboxes[indexParent1].sub_categories[index].status_code = 0;
}
this.setState({
checkboxes
});
}
请帮我解决这个问题。
【问题讨论】:
标签: reactjs react-native react-redux