title: How to update each and every keys of redux state by iteration with immutable principle
body: <p>I have a redux state as follows:-</p>
  
  <pre><code>data = {"facebook":true,"twitter":false,"google":false,"instagram":false,"watsapp":false}
  </code></pre>
  
  <p>I will be passing the key values in action ex:-("facebook","twitter")</p>
  
  <p>lets say i passed "facebook".
  Then I want the state to be updated to </p>
  
  <pre><code>{"facebook":true,"twitter":false,"google":false,"instagram":false,"watsapp":false}
  </code></pre>
  
  <p>here is my reducer function</p>
  
  <pre><code>function data = (state=initialstate,action) =&gt; {
     return {...state, [action.account]=true}
  }
  </code></pre>
  
  <p>For first time, it will give desired result.</p>
  
  <pre><code>{"facebook":true,"twitter":false,"google":false,"instagram":false,"watsapp":false}
  </code></pre>
  
  <p>Now lets say, I am passing the key "twitter"</p>
  
  <p>What I want:</p>
  
  <pre><code>{"facebook":false,"twitter":true,"google":false,"instagram":false,"watsapp":false}
  </code></pre>
  
  <p>What I was getting with above reducer function (as expected)</p>
  
  <pre><code>{"facebook":true,"twitter":true,"google":false,"instagram":false,"watsapp":false}
  </code></pre>
  
  <p>So I updated my reducer function to as following:-</p>
  
  <pre><code>function data = (state, action) =&gt; {
    Object.keys(state).forEach(function(key) {
      if(key!=action.account){
        state[key]=false; 
      } else {
        state[key]=true; 
      }
     });
    return state
  }
  </code></pre>
  
  <p>But this is against redux principle of immutable data.
  As I am using selector as well, it is showing some unexpected behaviour.</p>
  
  <p>How to update my reducer function which will set all the previously set values to <strong>false</strong> and will only set the current key to <strong>true</strong> keeping in mind immutable data principle of redux</p>