This answer might help you:
What is mapDispatchToProps?
mapDispatchToProps exists to make the reducers accessible through the component, when following a Container > Component pattern.
For example, i have these reducers:
const updateToPreviousMonth = (state) => {
let newState = state,
currentMonth = newState.get('currentMonth');
let previousMonth = sanitizedDate(moment(currentMonth).subtract(1, 'month'));
return newState.set('currentMonth', previousMonth);
};
const updateSelectedDate = (state, action) => {
return state.set('selectedDate', action.selectedDate);
};
export default (state = initialState, action = {}) => {
switch (action.type) {
case constants.SET_TO_PREVIOUS_MONTH:
return updateToPreviousMonth(state);
case constants.UPDATE_SELECTED_DATE:
return updateSelectedDate(state, action);
default:
return state;
}
};
The constants are the Actions, and the functions (reducers) which return the changed state.
const mapDispatchToProps = {
setToPreviousMonth: CalendarViewRedux.actions.setToPreviousMonth,
updateSelectedDate: CalendarViewRedux.actions.updateSelectedDate
};
export class CalendarView extends PureComponent {
componentDidMount() {
this.props.loadSchedules();
}
render() {
return (<CalendarViewRender
{...this.props} />);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(CalendarView);
On this example, i am passing the actions in mapDispatchToProps, and when called, they will activate the reducers from before, since i used mapDispatchToProps, they are now available in the CalendarView component.
Hope this helps, please mark as solved if this was helpful.