2

Is it possible to dispatch action outside React component?

import dispatch from 'react';
...
dispatch(actionCreator())

or:

bindActionCreators(actionCreator, dispatch)();

has no effect.

(FYI, I am trying to invoke action from axios interceptor - I just have found redux-axios-middleware, but I would like not to integrate it yet).

IProblemFactory
  • 9,551
  • 8
  • 50
  • 66
  • If you want to dispatch the action outside of react/redux you should subscribe to store and then dispatch the action. More info: http://redux.js.org/docs/api/Store.html#subscribe, but it is unlikely you would need to do it, what are trying to achieve ? – Shota Sep 21 '17 at 15:03
  • 2
    `dispatch` is not a function from the react module, it is a function on your redux store. You can call it wherever you'd like in your code, but you'll need a reference to your store to call `dispatch`. See: https://stackoverflow.com/questions/45043219/calling-dispatch-function-from-a-blank-javascript-file – forrert Sep 21 '17 at 15:11

0 Answers0