dsdenes / react-redux-action-provider

Automatically maps your action creators to your Redux store, and provides them to the child components through this.context.actions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This context provider component maps your action creators to your Redux store, and provides them to the child components through this.context.actions.

This saves you writing mapDispatchToProps boilerplate in every component.

Install

$ npm install react-redux-action-provider

Usage

actions.js

export function signIn() {
  dispatch => {
    // Sign in 
  }
}

export function signOut() {
  dispatch => {
    // Sign out 
  }
}

index.js

import {
  signIn,
  signOut
} from './actions';

import ActionProviderCreator from 'react-redux-action-provider';

const ActionProvider = ActionProviderCreator({
  signIn,
  signOut
});
- <Provider store={store}>
-   <App />
- </Provider>
+ <Provider store={store}>
+   <ActionProvider>
+     <App />
+   </ActionProvider>
+ </Provider>

MyComponent.js

+  MyComponent.contextTypes = {
+    actions: PropTypes.object
+  };
render() {
  // this.context.actions.signIn();
  // this.context.actions.signOut();
}

About

Automatically maps your action creators to your Redux store, and provides them to the child components through this.context.actions


Languages

Language:JavaScript 100.0%