Skip to content

Instantly share code, notes, and snippets.

@LucaColonnello
Last active May 23, 2016 08:58
Show Gist options
  • Select an option

  • Save LucaColonnello/fbc9faa28f8db8a9adba12db9dbdda56 to your computer and use it in GitHub Desktop.

Select an option

Save LucaColonnello/fbc9faa28f8db8a9adba12db9dbdda56 to your computer and use it in GitHub Desktop.
Redux bind nested action creators
import { bindActionCreator } from 'redux';
export default function bindNestedActionCreators(actions, dispatch) {
if (typeof actions !== 'function' && (typeof actions !== 'object' || actions === null)) return false;
let dispatchedActions;
if (typeof actions === 'object') {
dispatchedActions = {};
Object.keys(actions).forEach(a => {
const newActions = bindNestedActionCreators(actions[a], dispatch);
if (newActions) dispatchedActions[a] = newActions;
});
}
if (typeof actions === 'function') {
dispatchedActions = bindActionCreator(actions, dispatch);
}
return dispatchedActions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment