I need to have a nested state in my main component. I came up with having the initialState which I was going to use for the reset feature.
constructor() {
...
this.initialState = {
...
employees: {
manager: {
name: 'Andrew',
age: 27
}
developer: {
name: 'David'
age: 32
}
}
...
};
this.state = this.initialState;
But it doesn't work with React. As setState can't handle nested properties and both this.state and this.initialState are just references to the same object. I've tried spread operator, Object.assign and finally came across a immutability-helper
But I still can't understand how to set state in the constructor and how to "reset" the employees part of the state later on.
Other properties of state are flat.