i'm new at React js, i want to ask, i have a object, i want to update some property from the object, but when i change one property from the object, another property is update too and the value is undefined i try to using spread operator but when i running, it show error not defined. This is my code
export default class Message extends React.Component {
constructor(props){
super(props);
this.state = {
isLoggedIn: SystemStore.isLoggedIn(),
profile: ProfileStore.getProfile(),
messageInfo: {
fullName: SystemStore.systemUser().fullName,
site: '',
email: '',
phone: '',
},
subject: '',
description: '',
type: '',
errorMessage: '',
errorDialog: '',
isSubmited: false,
successMessage: '',
submitting: false
};
....
clearForm(){
this.setState({
messageInfo: {
...messageInfo, //in here i get error messageInfo is not defined
subject: '',
description: ''//if doing this i get error SyntaxError
}})
}
handleProfileChange(){
this.setState({
messageInfo: {
....messageInfo, site: ProfileStore.getProfile().primarySite.name,
}});
console.log(this.state.messageInfo.fullName);
console.log(this.state.messageInfo.site);
}
handleSubjectChange(evt){
this.setState({ subject: evt.target.value }, () => {
if(this.state.messageInfo.subject === 'PRAYER') {
this.setState({ type: 'REQUEST' });
} else if(this.state.messageInfo.subject === 'ADDRESS') {
this.setState({ type: 'INFORMATION' });
} else if(this.state.messageInfo.subject === 'VISIT'){
this.setState({ type: 'REQUEST' });
}
});
}
handleMessageChange(evt){
this.setState(prevState=>({
messageInfo: {
...prevState.messageInfo, description: evt.target.value
}}));
}
Any suggestion where i got wrong? Thank you