Answer the question
In order to leave comments, you need to log in
How to replace object property inside state object?
There is a component inside it:
this.state = {
sms: {
code: null,
startTime: 60,
disabled: false,
},
};
I need to change only the disabled value inside the sms
object
. I do this:
someFunction = () => {
this.setState({...this.state.sms, disabled: true});
}
And there is a complete rewriting of the sms object
Question: how to change only the disabled value?
Answer the question
In order to leave comments, you need to log in
It is necessary to rewrite the sms object
someFunction = () => {
const {sms} = this.state;
sms.disabled = true;
this.setState({sms});
}
someFunction = () => {
this.setState({sms: {...this.state.sms, disabled: true}});
}
someFunction = () => {
this.setState(prevState=>({sms: {...prevState.sms, disabled: true}}));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question