KickstarterSarah Groff Hennigh-PalermoExplainer
Namespacing Actions for Redux
Summary
Kickstarter’s front-end team encountered a Redux action-namespacing problem when multiple instances of the same functional React component responded to actions intended for only one instance. They rejected local state because the application used functional components and redux-loop, which routes state updates and side effects through reducers, and they sought programmatic namespacing compatible with combineReducers and a low-surface-area component API. The team compared nested reducers, higher-order reducers, and a closure-based module pattern; the latter met the stated constraints with namespaced actions, wrapper components, reducers, and a namespace returned by a factory that defaults to a UUID. Namespaces must be preserved when reducers trigger further actions, including redux-loop results, and complex composition can lose the required binding. The approach has worked for most reusable and compound components, while possible performance costs from many reducers remain a future concern.
Context
Multiple instances of the same Redux-backed component responded to actions intended for only one instance. The team wanted namespacing that avoided local state, worked with combineReducers, could be applied programmatically, and imposed little complexity on developers instantiating reusable components.
Approach / What changed
The team adapted the JavaScript module pattern using a namespacing function and utility functions. A reusable component provides namespaced actions shaped as { type, namespace, ...otherPayload }, a wrapper component accepting state, dispatch, and optional configuration, a reducer that preserves the namespace through actions returned by redux-loop, the namespace itself, and initial state. The namespace can default to a UUID, while factory arguments support wrapped or themed components.
Takeaways
The module-pattern solution met the requirements for avoiding local state, supporting combineReducers, enabling programmatic namespacing, and keeping instantiation to state and dispatch.
Actions dispatched by reducers must retain their namespace, including actions returned by redux-loop; the implementation usually binds actions to reducers during initialization.
The approach has worked for reusable and compound components, but lost bindings in some complex compositions and may face performance costs if the number of reducers becomes too large.
Source and freshness
- Source
- medium.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.