4 ms·
One major problem we had with Redux, especially in a large organization where reusability is very important, is that we found it hard to reuse most of the redux
by sktrdie 9y ago
One major problem we had with Redux, especially in a large organization where reusability is very important, is that we found it hard to reuse most of the redux logic (reducers/thunks/selectors). The pure components were easily shared across different teams, but most of the other stuff was too much redux or app-specific that we couldn't really reuse it.
We experimented with simply using large stateful react components instead of redux for certain areas of the app, and our reusability improved dramatically.
Any thoughts on how this is tackled by some hardcore redux users?
- ff_ 9y agoIt is a general problem (that is, not only Redux has it, but basically any React-based thing), and the pattern that works best for reusability (in my esperience) is the "pure component sandwich": you have a pure component which takes a bunch of functions as parameters (and is reusable, no framework-specific stuff) and wrap it in the app-specific component which implements these functions for the current app.
- daveidol 9y agoDefinitely agree, but I think the parent commenter was asking how to reuse redux-specific code, such as reducers, actions, etc.
- daveidol 9y agoReducer, middleware, and "action creator" factories that take config will allow for a pretty high level of reusability. We have several internal redux libraries of generic reducers, middleware, etc. and they all export factories that return these things instead of naked reducers, middleware, etc. The factories can take config for which action types to handle, etc.
- Klathmon 9y agoIn our case if we want to share some of the logic in a reducer/action-creator or something else, we write "helper" functions that handle the heavy lifting, and call them from the action-creator. This way we can easily test and reuse the actual "hard logic" for those parts, don't need to worry about trying to reuse the actual Redux stuff, and can add/modify the input or result from the helper functions slightly if needed per app. Yes, it's more boilerplate, but it's served us well.