How can I update a value within a react state object when that value is an object? Example:
this.state = { nestedObj: { x: 0, y: 5 } };
at a later time, I want to update that nestedObj with an arbitrary object based on the object created from a JSON.parse based on user input.
I try the following and it does not work:
const newObj = {nestedObj: { x: 0, arbitraryKey: 'bla', anotherOne: { h: 0 }}};
this.setState(newObj);
I would really like to just blow away whatever object resides at this.state.nestedObj and replace it with whatever object is defined at newObj. How can I do that? I have other keys in my this.state so it would be ideal if this only affected the nestedObj but I'm not super picky.
Thanks!
this.setState({nestedObj: newObj})?