简体   繁体   中英

Reducers in React-Redux

I have just started learning to react and redux. I was just wondering how should I create my multiple reducers? Should my reducers be based on my action type? for example, if I have a e-commerce web, one reducer should be for adding, removing and updating to cart. Another reducer will be for clicking an item an displaying the information. It is supposed to be like that I assume.

You can have multiple objects in a reducer to point your different needs. Your component can then listen to the changes of that particular object alone. You should make use of the method combineReducers from redux to achieve this. Use this link https://redux.js.org/recipes/structuring-reducers/using-combinereducers/ to explore more about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM