title: How to Generate New Key for Redux State Item?
body: <p>I'm having a little trouble figuring out what the best practice may be for adding new items to my React/Redux state with new keys.</p>
  
  <p>Given the state:</p>
  
  <pre><code>const initialState = {
    "routines": {
      "1": {
        "id": 1,
        "name": "Routine 1",
      },
      "2": {
        "id": 2,
        "name": "Routine 2",
      }
    }
  }
  </code></pre>
  
  <p>Let's say I want to add a new item into this state. Where should I put the logic for coming up with the new ID? </p>
  
  <ol>
  <li>Should that be a property of the form whose submittal triggers the ADD_ROUTINE action?</li>
  <li>Should the logic for generating the new id be in the reducer?</li>
  </ol>
  
  <p>Here is my best attempt, but I'm wondering if there is a better way to do this.</p>
  
  <pre><code>import { ADD_ROUTINE } from '../actions/routineActions'
  
  function routineReducer(state={}, action) {
    switch (action.type) {
      case ADD_ROUTINE:
        newState = {...state}
        number_of_keys = Object.keys(newState).length
        new_id = number_of_keys + 1
        return {
          ...state,
          new_id: {
            id: new_id,
            name: action.name,
            days: []
          }
        }
      default:
        return state
    }
  }
  
  export default routineReducer
  </code></pre>