I have the following state in a React.Component
class:
this.state = {
stuff: {
stuffData: [],
loading: true,
},
moreStuff: {
...
}
}
Inside a function, after a button click I want to update the state of stuff
to loading
.
It works if I do it the following way:
const { stuff } = this.state;
const newStuff = stuff;
newStuff.loading = true;
this.setState({ stuff: newStuff };
But I wanted to do it like this (don't get expected result):
const { stuff } = this.state;
this.setState({ stuff: {loading: true, ...stuff } });
What am I missing?