title: React Redux - Reducer with CRUD - best practices?
body: <p>I wrote simple reducer for <code>User</code> entity, and now I want to apply best practices for it, when switching action types and returning state. Just to mention, I extracted actions types in separate file, <code>actionsTypes.js</code>. </p>
  
  <p>Content of <code>actionsTypes.js</code> :</p>
  
  <pre><code>export const GET_USERS_SUCCESS = 'GET_USERS_SUCCESS';
  export const GET_USER_SUCCESS = 'GET_USER_SUCCESS';
  export const ADD_USER_SUCCESS = 'ADD_USER_SUCCESS';
  export const EDIT_USER_SUCCESS = 'EDIT_USER_SUCCESS';
  export const DELETE_USER_SUCCESS = 'DELETE_USER_SUCCESS';
  </code></pre>
  
  <p>First question, is it mandatory to have actions types for <code>FAILED</code> case? For example, to add <code>GET_USERS_FAILED</code> and so on and handle them inside usersReducer?</p>
  
  <p>Root reducer is: </p>
  
  
  
  <pre><code>const rootReducer = combineReducers({
      users
  });
  </code></pre>
  
  <p>There is code of usersReducer, and I put comments/questions inside code, and ask for answers (what are best practices to handle action types): </p>
  
  <pre><code>export default function usersReducer(state = initialState.users, action) {
      switch (action.type) {
          case actionsTypes.GET_USERS_SUCCESS:
          // state of usersReducer is 'users' array, so I just return action.payload where it is array of users. Will it automatically update users array on initial state?
              return action.payload;
          case actionsTypes.GET_USER_SUCCESS:
          // What to return here? Just action.payload where it is just single user object? 
              return ;
          case actionsTypes.ADD_USER_SUCCESS:
          // what does this mean? Can someone explain this code? It returns new array, but what about spread operator, and object.assign?
              return [...state.filter(user =&gt; user.id !== action.payload.id),
                  Object.assign({}, action.payload)];
          case actionsTypes.EDIT_USER_SUCCESS:
          // is this ok?
              const indexOfUser = state.findIndex(user =&gt; user.id === action.payload.id);
              let newState = [...state];
              newState[indexOfUser] = action.payload;
              return newState;
          case actionsTypes.DELETE_USER_SUCCESS:
          // I'm not sure about this delete part, is this ok or there is best practice to return state without deleted user?
              return [...state.filter(user =&gt; user.id !== action.user.id)];
          default:
              return state;
      }
  }
  </code></pre>