title: React : how to update states which have both mutable and immutable values
body: <p>In Javascript, <a href="https://www.youtube.com/watch?v=9M-r8p9ey8U" rel="nofollow noreferrer">string, integer and boolean values are immutable, but objects and arrays are mutable.</a></p>
  
  <p>How should we update states in React, if states have both types of values?</p>
  
  <p>e.g.</p>
  
  <pre><code>constructor(props) {
      super(props);
      this.state = {
          success: false,
          error: false,
          errorMessages: {}
      };
  }
  </code></pre>
  
  <p>Assuming that you need to upgdate all of the properties (<code>success</code>, <code>error</code>, <code>errorMessages</code>) at once, what would be best way to achieve it?</p>
  
  <p>At least I'm sure that <code>errorMessages</code> shouldn't be updated directly, because it's mutable by nature, but what about the rest of them?</p>
  
  <p>I tried something like the following, but this ends up in a wrong result.</p>
  
  <pre><code>const errorMessages = {
      ...this.state,
      "errorMessages": error.response.data,
  };
  
  this.setState({
      errorMessages,
      success: false,
      error: true,
  });
  
  //The errorMessages property will have "success" and "error" property in it
  </code></pre>