D
D
DarthJS2018-06-15 16:41:13
React
DarthJS, 2018-06-15 16:41:13

How to call one action in another action using redux-thunk?

It is necessary to call an action inside another action, but the call does not go through at all.
Tell me why it is not called and how to do it correctly?

actionsA.js

export const actionFromA = data => (dispatch) => {  }

actionsB.js
import {actionFromA} from '****';

export const actionFromA = data => async (dispatch) => {  
// Вот тут нужно вызвать импортированный action
actionFromA();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-06-15
@DarthJS

export const actionFromA = data => async (dispatch) => {  
  dispatch(actionFromA());
}

At least read the documentation. The dispatch
argument is the store.dispatch function . The storage state update is triggered by passing an action object to this function: Your action creator actionFromA() returns a similar object. And call: Equivalent to:
store.dispatch({ /* объект возвращаемый actionFromA */ });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question