0

hope doing well all of you. I'm not gonna ask coding question. I start new project on react & I'm fresher. I need to know, do we need separate reducers for each component. (e.g. let say I have category component in which I'll show all categories & give a form to insert new category. Now I've another component called tags. Same thing will happen here. So do I need CategoryReducer & TagReducer separate).

Shivam Verma
  • 905
  • 1
  • 8
  • 20
  • You do not need to have separate reducer for each component. Your should separate them based on what data they store and later combine them. If CategoryReducer contains data that are not related to data in TagReducer then it's all right – kenodek Dec 11 '19 at 13:01
  • Thanks @DominikTargosz for explaining me. I need your little favour, do you know any best tutorial or article or anything related to How react works with redux. – Shivam Verma Dec 11 '19 at 13:19
  • @ShivamVerma official docs are enough for understanding the concepts https://redux.js.org/basics/usage-with-react – Prabhat Mishra Dec 11 '19 at 13:21
  • @ShivamVerma I recommend TraversyMedia tutorial but offical documentation is also fine. There is plenty of tutorials about Redux – kenodek Dec 11 '19 at 13:24

2 Answers2

1

As per my understanding,If your app will be growing big in future and you want to keep the functionality segregated,It will be good to have a separate reducer for a specific functionality.As this will also help you to convert your bulky application in micro service or mono-repo app.

Let's say for example we have a shopping site. I know this application will be growing big with multiple functionality so we should spend some efforts keep containers and specific reducers for those containers segregated.

Containers I will be build for a shopping site.
1.Products
2.Payments Details
3.Orders
etc..
I will prefer to keep the reducers segregated for these functionalities.

Please correct me,if someone has any other view point.

Prabhat Mishra
  • 951
  • 2
  • 12
  • 33
  • Thanks a lot @Prabhat Mishra for your explanation. I want your favour, please share some good article or tutorial about How react works with redux & how its flow goes. – Shivam Verma Dec 11 '19 at 13:23
  • @ShivamVerma https://medium.com/javascript-in-plain-english/the-only-introduction-to-redux-and-react-redux-youll-ever-need-8ce5da9e53c6 – Prabhat Mishra Dec 11 '19 at 13:25
0

Its is not mandatory to have a separate reducer for each component but it is a good coding practice to have separate reducers, you can achieve it using "combineReducers"

Arpit Bhatia
  • 173
  • 1
  • 8