I am attempting to use the spread operator to copy an object with nested objects.
An example of my code looks like this:
constructor(props) {
super(props)
this.state = {
copy1: {...this.props.originalObject},
copy2: {...this.props.originalObject}
}
This works fine for the outer object values. Hewever, when I make changes to the nested objects in copy1, they are also changed in copy2. This tells me that it still copying the inner objects by reference. What can I do to get around this?
Duplicate Answer?
This question that was linked as a duplicate to my question does not really seem to help as it is geared towards a specific situation and is using Redux. I am not using Redux.