Should I use one or several action types to represent this async action?

前端 未结 3 1559

I\'m building a front-end for a search system where almost all user actions need to trigger the same async action to re-fetch search results. For example, if a user enters a key

3条回答
  •  天涯浪人
    2021-02-13 21:24

    I fully agree with Nathan’s answer.

    I just want to add that in order to tell whether actions A and B are really one or two actions, you need to ask yourself: “If I change how some reducers react to A, will I also need to change how they react to B?”

    When the handlers change together in the reducer code, it’s likely they should be a single action. When their changes may not affect each other, or if many reducers handle just one of them but not the other, they should probably stay separate.

提交回复
热议问题