title: Cloning an object within a redux reducer
body: <p>I've recently learned React and Redux, and right when I thought I was getting the hang of it I've been hung up on this.</p>
  
  <p>In my reducer I'm under the impression that the spread operator should create a new instance of the object at a difference memory location. However, using <code>===</code> to compare the objects returns true which I believe means the objects are the same instances.</p>
  
  <pre><code>const initState = {
  
      loadcases: {
          1: {
              isActive: false,
              profile: 'UB'
          },
          2: {
              isActive: true,
              profile: 'PFC'
          }
      }
  }
  
  
  const designInput = (state=initState, action={}) =&gt; {
  
      let newState = {...state}; //clone design input state
      console.log(newState.loadcases === state.loadcases)
      // Prints: TRUE ---- WHYYYYYYY????????????
  
      // goes on to modify newState before returning it. 
  }
  </code></pre>
  
  <p>The redux logger is showing my previous state to already equal the new state which has me thinking that this here is interfering with the store directly. I've read through some redux docs and other posts which make me believe I have set everything else up correctly.</p>
  
  <p>Any resources to educate me more on this issue is also much appreciated.</p>
  
  <p><strong><em>UPDATE:</em></strong></p>
  
  <p><a href="https://stackoverflow.com/a/60963085/5553768">Jayce's answer</a> was exactly what was happening.</p>
  
  <p>This <a href="https://stackoverflow.com/a/122704/5553768">SO post</a> outlines which method for a deep clone will be suitable. For me, it's likely I'll want to store dates and other data so I've chosen to use <a href="https://lodash.com/docs/4.17.15#cloneDeep" rel="nofollow noreferrer">lodash cloneDeep method</a>.</p>
  
  <p>So now: <code>console.log(cloneDeep(state) === state.loadcases); // false</code> </p>