Answer the question
In order to leave comments, you need to log in
How to set state dynamically?
There is the following code:
getval = ( propName, value ) => {
const { formInfo } = this.state;
this.setState( {
formInfo[propName]: value
} )
}
state = {
formInfo: {
name: '',
tel: '',
email: '',
subject: '',
text: ''
}
}
Answer the question
In order to leave comments, you need to log in
setVal = (propName, value) => {
this.setState(state => ({
formInfo: {
...state.formInfo,
[propName]: value,
}
}));
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question