如何在this.setState中更改嵌套对象的值
state = {
employee: {
id: 0,
firstName: '',
lastName: '',
email: '',
phone: '',
accountNumber: '',
rate: '',
},
handleDate = e => {
const date = e.target.id;
const value = e.target.value;
this.setState(prevState => ({
employee: {
[date]: value,
},
}));
};
当我尝试在输入中添加一些内容时,我的React状态会自行重置,并仅添加用户输入日期。