Open jedwards1211 opened 7 years ago
In fact, the Redux docs now have an excellent guide on doing this here: https://github.com/reactjs/redux/blob/master/docs/recipes/reducers/ReusingReducerLogic.md
I'm using the Redux guide for creating split reducers, but I'm not sure how to map these as props for a component. The guide above doesn't follow up on this. What's the next step?
@georgeawwad are you looking for react-redux?
Right. I was only asking my question here because your docs link led me to a potential solution with my project. It's not specifically related to this repo.
Thought you might want to consider this: The solution I've settled on for this kind of thing in my own projects is to use the same reducer and action creator code, but with action types prefixed differently for each reducer mount point, as depicted in the code below. I would love if
redux-form
worked this way.It took a long long time before I had the idea to do things this way but once I did I wish I had thought of it at the very beginning.
Advantages:
Disadvantages:
I even created
prefixReducer
andprefixActionCreator
functions in mymindfront-redux-utils
package to decorate existing reducers and action creators that weren't designed to be created with an action type prefix option.Example with
prefixReducer
andprefixActionCreator
(which I only really like to do if I'm using 3rd-party reducers/action creators):