Redux Module ( Proposal )
Reduced boilerplate for your redux, inspired from Ducks: Redux Reducer Bundles and personally felt the pain of writing too much boilerplate for simple redux apps.
Usage
- Create Redux Module
// sideNav.js// Simple module that is suppose to open and close SideNavigation (hamburger menu) of an app. ; const module = ; ;
- Use it with combineReducers (if multiple reducers)
;; ; ;
- Or if you just want to extract reducer from a module
;const reducer = ;
- In your Containers/Components use connect the usual way. redux-modules automatically creates key mirroed actions and to use them just extract actions from your modules like below,
;; @ { const appState dispatch = thisprops; return <div> <button onClick= >Open SideNav</button> <SideNavigation isSideNavOpen=appStateisSideNavOpen /> </div> ; }
Where the heck are Actions ?
Redux Modules auto generates mirrored key value actions based on function names provided in reducers
object when creating Redux Module.
For above reducer you will have following actions available,
; console; //{ openSideNav: 'openSideNav', closeSideNav: 'closeSideNav' }
You can now use these actions in your usual way ie,
; // somewhere in the component