在我的react.js应用中,我的数组处于状态:
constructor(props) {
super(props);
this.state = {
userRecord: {
userName: '',
userEmail: '',
userAge: '',
userHeight: '',
userRace: '',
userGender: '',
createdAt: undefined,
updatedAt: undefined
}
}
}
然后我调用一个函数,尝试设置每个值的状态
this.setState({
userRecord.userName: newuserDocs[0].userName,
userRecord.userAge: newuserDocs[0].userAge,
userRecord.userHeight: newuserDocs[0].userHeight,
userRecord.userRace: newuserDocs[0]. userRace,
userRecord.userGender: newuserDocs[0].userGender,
userRecord.userEmail: newuserDocs[0].userEmail,
});
但是我收到一个错误,提示userRecord和每个值之间的时间段不正确。
如何正确设置这些值的状态?