Redux can I use one action type in separate reducers?

I think that's perfectly fine. There is no place to states that Actions and Reducers have a 1:1 mapping. In fact, creator of Redux explicitly says that there is no relation between them, many reducers can react to a single actions, a single reducer can react to multiple actions.

I think he says it best: https://github.com/reduxible/reduxible/issues/8

Tweet: https://twitter.com/dan_abramov/status/691608868628119552

Relevant SO: Redux: Why not put actions and reducer in same file?


I had a similar question if I could use the same action type name in two or more separate reducers and the answer is definitely no if there is not a very exceptional case.

Why not?

Even we write reducers separately after combining them by combineReducers function when we dispatch the action all reducers are called their switch case statements.

Reducer one:

export const postReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case "SET_DATA":
      const { posts } = action.payload;
      return {
        ...state,
        posts: posts,
      };
  }
};

Reducer two:

export const commentReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case "SET_DATA":
      const { comments } = action.payload;
      return {
        ...state,
        comments: comments,
      };
  }
};

So when we dispatch an action with type SET_DATA both reducer will be called and if payload value is

{
  comments: ['comment one', 'comment two'] 
}

post reducer will set its posts to undefined.

A better solution would be to name types like this:

case "SET_POST_DATA":

case "SET_COMMENT_DATA": 

to avoid collision between two reducer's actions.

The convention is that when action is called there is only one reducer who is responsible to answer that action otherwise it can cause misunderstanding for other developers