I normalize all my objects, but I do not use normalizr.
I like to normalize because it makes the code more readable. An example is below. It also makes it easier to access objects and eliminate duplication. For example, if you subscribe to the todo element in the elses user list, you either need to return a duplicate version of this list in the subscribedTodos subscribedTodos , or you need to know the user ID and todo of the other todo in order to get to it.
Back to readability: Which ones are better to read / understand?
function rootReducer (state, action) { const { type, payload } = action; if(action.type === MODIFY_TODO) { return { ...state, users: { ...state.users, [payload.userID]: { ...state.users[userID], todos: { ...state.users[userID].todos, [payload.todo.todoID]: { ...state[userID].todos[todoID], ...todo } } } } } } else { return state; } } function rootReducer (state, action) { const { type, payload } = action; if(type === MODIFY_TODO) { return { ...state, todos: { state.todos[payload.todo.id]: { ...state.todos[payload.todo.id], ...payload.todo } } } } else { return state; } }
source share