我在做一个待办事项的申请。这是违规代码的一个非常简化的版本。我有一个复选框:
<p><input type="checkbox" name="area" checked={this.state.Pencil} onChange={this.checkPencil}/> Writing Item </p>
下面是调用复选框的函数:
checkPencil(){
this.setState({
pencil:!this.state.pencil,
});
this.props.updateItem(this.state);
}
updateItem是一个映射到调度到redux的函数
function mapDispatchToProps(dispatch){
return bindActionCreators({ updateItem}, dispatch);
}
我的问题是,当我调用updateItem操作并console.log状态时,它总是落后一步。如果复选框未选中并且不是true,我仍然会得到传递给updateItem函数的true状态。我是否需要调用另一个函数来强制更新状态?
https://stackoverflow.com/questions/38558200
复制相似问题