1.0.3 • Published 7 years ago
react-redux-action-provider v1.0.3
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();
}
1.0.3
7 years ago