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();
漫思