Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shall we use multiple combine reducers?

I have three reducers

  • Home
  • Listing
  • Detail

I have one combine reducer for above three. But I want to divide project structure into multiple reducers. Is it a good practice to have multiple combine reducer in the project?

like image 297
Abhishek Avatar asked Aug 04 '17 04:08

Abhishek


1 Answers

Yes, you can have multiple combineReducers in your App, You can at the top level combine reducers Home , Listing and Detail and even split each individual reducers into multiple and combine them into one.

According to the Redux docs:

You may call combineReducers at any level of the reducer hierarchy. It doesn't have to happen at the top. In fact you may use it again to split the child reducers that get too complicated into independent grandchildren, and so on.

Some more description about combineReducer:

As your app grows more complex, you'll want to split your reducing function into separate functions, each managing independent parts of the state.

The combineReducers helper function turns an object whose values are different reducing functions into a single reducing function you can pass to createStore.

The resulting reducer calls every child reducer, and gathers their results into a single state object. The shape of the state object matches the keys of the passed reducers.

like image 102
Shubham Khatri Avatar answered Oct 02 '22 04:10

Shubham Khatri