state连续调用的问题

onChange = (k: any, v: any) => {
console.log('v', v);
const form = _.cloneDeep(this.state.form);
_.set(form, k, v);
this.setState({
form
});
};
onChange();
onChange();

因为 setState 是异步的

连续调用两次肯定是有问题的

 

onChange = async(k: any, v: any) => {
console.log('v', v);
const form = _.cloneDeep(this.state.form);
_.set(form, k, v);
await this.setState({
form
});
};

 

await onChange();
await onChange();

 

posted on 2022-06-25 14:28  漫思  阅读(19)  评论(0编辑  收藏  举报

导航