There is an essence of users, now I can display a list of users and add new ones.
in the future there will be another EDIT_USER_, as well as DELETE_USER_
I want to note that for each request a prelauder is needed, i.e.the isFetching field since the server does not work fast.

in this example
1) one isFetching is used for all types of action games, which is not good.
2) 1 reducer is used for compact code.(Which is good for me)

How from the point of view of architecture to make isFetching for each of the actions?
I know that you can create 6 reducers and everyone will have their own isFetching, but this will be a good readability.
You can leave one reducer as it is now and make isFetchingGetUsers isFetchingAddUser isFetchingEditUser isFetchingDeleteUser inside one reducer, but this option is also not very good, we get porridge from different field names

how to be? Could you tell me pliz.
Or should it still be divided into 6 viewers?

const initialState={isFetching: false, error: null, data:[]};

export default(state=initialState, {type, payload})=>{
  switch(type) {
    case'GET_USERS_REQUEST':
      return {...state, isFetching: true};
    case'GET_USERS_SUCCSESS':
      return {...state, isFetching: false, data: payload};
    case'GET_USERS_ERROR':
      return {...state, isFetching: false};

    case'ADD_USER_REQUEST':
      return {...state, isFetching: true};
    case'ADD_USER_SUCCSESS':
      return {...state, isFetching: false};
    case'ADD_USER_ERROR':
      return {...state, isFetching: false};

    default:
      return state;
  }
};

1 Answers 1

The state of the collection of users is best stored in a single viewer.
If an application is meant to work with one active entity, then it is better for it to make a separate reducer.In this case, it may be convenient to use one key for editing, saving and deleting.
If these keys are needed to work with the collection, for example, fast editing, adding and deleting in the table.You can use the collection of states:
{
  isFetching: {
   'ALL': false,
   '122bc-e43gf-24002-12ea1-ca785': true
  },
}

Where there is always a property for all entities and is optionally added for the necessary elements by id.