Search code examples
reduxreact-reduxreducersredux-reducers

If i have 100 reducers in my react app will all reducers get called when an action is dispatched?


If so will this lead to a performance issue ?

Secondly

Is there a way to specifically call a reducer without invoking all 100 reducers ?


Solution

  • This is specifically answered in the Redux FAQ:

    https://redux.js.org/faq/performance#wont-calling-all-my-reducers-for-each-action-be-slow

    It's important to note that a Redux store really only has a single reducer function.

    However, even if you happen to have many different reducer functions composed together, and even with deeply nested state, reducer speed is unlikely to be a problem. JavaScript engines are capable of running a very large number of function calls per second, and most of your reducers are probably just using a switch statement and returning the existing state by default in response to most actions.

    Also, "call a reducer" is the wrong mental model here. Actions are like "events" that are being broadcast - you don't ever "call a reducer" directly:

    https://redux.js.org/style-guide/style-guide#model-actions-as-events-not-setters