A
A
ar52016-04-24 18:00:11
JavaScript
ar5, 2016-04-24 18:00:11

Where should an async call be in Redux?

Hello, I am learning Redux and React, looking at examples. And one question arose where it is necessary to make an asynchronous call: in Actions or in middleWare. What is the difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-04-25
@ar5

In short - in actions.
In detail, then:
An asynchronous call is made with the participation of middleware in actions. This is the answer =)
On the shelves: redux-thunk is usually used , the code of which is very simple: if actionCreator returns a FUNCTION, then you need to throw store and dispatch into the function as arguments. Thus, from actions (actions) you will be able to perform asynchronous requests.
More details here
Also, there is a whole mini tutorial on redux.
---
For routing in response to an asynchronous request, you will have to use another middleware, this will be described in detail here , section: connecting redux . At the moment, almost everything is finished, I will publish it next week.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question