score:1

Accepted answer

nothing happens because the imported action creators are not bound to dispatch (unlike their counterparts on this.props.actions), so calling them simply returns an action object without triggering the reducer.

you can manually inject dispatch to your props and then pass it to the cleanup function, but the easiest solution is to install redux-thunk, and write your action creator like this:

export const cleanup = () => (dispatch, getstate) => {
  dispatch(cleanupx());
  dispatch(cleanupy());
  dispatch(cleanupz());
};

then you bind it at connect like you did for the other action creators, and call it from the component with this.props.actions.cleanup().

installation of redux-thunk is straightforward, just install the npm package and add it to the middleware of your store:

import { createstore, applymiddleware } from 'redux';
import thunk from 'redux-thunk';
import yourreducer from ...;

const store = createstore(
  yourreducer,
  applymiddleware(thunk)
);

Related Query

More Query from same tag