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
});
}
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?
Or... this.setState( prevState => ({ ...prevState, contractData:{...prevState.contractData, occasion: idenfifier} }));
Обсуждают сегодня