Похожие чаты

Hi, another question about ( extremely similar to another question

that i already did )
this.state = {
contractData: {
celebrity: null,
contractType: 1,
deliveryFrom: "",
occasion: 'BIRTHDAY',
},

If i want to change this state, i should do it in this way? :

changeOcassionOption = (idenfifier) =>{
const updatedContractData = {...this.state.contractData};
updatedContractData.occasion = idenfifier;
this.setState({
...this.state,
contractData: updatedContractData
});
}

2 ответов

14 просмотров
Isaac-. Автор вопроса

I make a copy of the state object, update this copy, and then in setState, i update the old key with new Data, am i right?

Isaac-. Автор вопроса

Or... this.setState( prevState => ({ ...prevState, contractData:{...prevState.contractData, occasion: idenfifier} }));

Похожие вопросы

Обсуждают сегодня

Карта сайта