Usage multiple view of same component with same reducer

163 Views Asked by At

I have created a view with store because have some header list components. In timeline we want to show 2 of this. Like belove. So should i remove the reducer dependency? What would your solution?

enter image description here

1

There are 1 best solutions below

6
phry On

You should not write a Redux reducer "for a view" in the first place. Redux is your data layer. It should not contain your data in a format that is especially readable for a certain component, but it should contain the data for your application - and each component can use selectors to get the data out of it that it needs. Having one reducer that exactly has the right shape and data for a component/view is essentially an antipattern. It should not have a lot of influence on the shape or contents of your Redux store if you have one view, two views, or five views displaying that data.

I highly recommend you read the Redux Style Guide as I guess you might have a few other ideas that might be going against our recommendations.

Also, as you are using the word "reducer", and not the more modern "slice", you might be using an outdated style of Redux. Just to make sure you are aware of this: modern Redux does not use switch..case reducers, ACTION_TYPES, immutable reducer update logic, connect/mapStateToProps and createStore/applyMiddleware any more. Modern Redux is about 1/4 of the code and avoids common pitfalls. You can read about it here.

If you need a tutorial that shows modern Redux and explains how it should be used, I would recommend you to look at the official Redux tutorial.