title: Update state with dynamically constructed object using reducers in React
body: <p>I have an array of values which are set in state to a boolean. I need to loop through the array and set each value to the payload (true). The code below works correctly but I'm looking for a way to achieve the same result for an arbitrary amount. </p>
  
  <pre><code>criticals = ["critical-1-524", "critical-4-572", "critical-15-24", "critical-30-48"]
  
  return {
        ...state,
        mapboxToggleLayers: {
          ...state.mapboxToggleLayers,
          [criticals[0]]: action.payload,
          [criticals[1]]: action.payload,
          [criticals[2]]: action.payload,
          [criticals[3]]: action.payload
        }
      }
  </code></pre>
  
  <p>Here is my working version but this deletes all the values in it's state object.</p>
  
  <pre><code>return {
    ...state,
    mapboxToggleLayers: {
      ...state.mapboxToggleLayers
      [criticals.map(el =&gt; {
        let critObj = {}
        return critObj[`${el}`] = action.payload
      })]
    }
  }
  </code></pre>