Redux Action Wrapper
This simplifies your mapDispatchToProps
and removes a significant amount of boilerplate by wrapping your action modules with the dispatch function. It takes an object that contains functions and returns those functions wrapped in the dispatch method. The object is traversed recursively. Non-functions are ignored.
Basic Usage
The action wrapper is only used in the mapDispatchToProps function that you pass to redux's connect
.
; { return ;}
API
Only one function is provided.
var actions =
Arguments
actionsObject
is an object, possibly nested, containing action functions.dispatch
is the dispatch method provided by react-redux.
Return Value
The actions object returned can be returned from mapDispatchToProps
directly.
Using it in your components
All functions on the object passed to actionWrapper
are wrapped in the dispatch
function provided by Redux. You access them through this.props
.
// for the root levelthisprops; // for nested objectsthispropsuserActions; // and double nested is the samethispropsuserActionspreferences;
Usage with some context
;; ;; ; Component { if !thispropsuser thispropsuserActions; // <---- ACTION USAGE thisprops; // <------------ ACTION USAGE } { if thispropsuser return <span>thispropsusername</span>; else return <span>Loading...</span>; } { return ;} { return store;} mapStoreToProps mapDispatchToPropsMyComponent;