title: Implementing undo/redo function in react
body: <p>I am trying to implement simple undo/redo function in my react app. So I am trying to maintain an array with old state values. But when I check the values of the old states, its all updated with the new state.</p>
  <p>state :</p>
  <pre><code>state = {
          schedule : [],
          loads:[],
          undo:[],
          redo:[]
      };
  
  const redoUndoObj ={
          oldStateSchedule : [...this.state.schedule],
          oldStateLoads : [...this.state.loads]
    }
         
    this.setState({ undo : [ ...this.state.undo , redoUndoObj]});
  </code></pre>