R
R
Roman2017-05-14 16:10:15
React
Roman, 2017-05-14 16:10:15

How to chain requests in React + Redux?

It is necessary to implement such a chain of asynchronous requests
Download Facebook SDK asynchronously -> Check if the user is authorized -> If authorized, get additional information on it
FbActions is responsible for asynchronous loading of the SDK, UserActions is responsible for authorizing the user and receiving data on him
The question is: how these actions combine? return promises and write a chain at the container level:
sdkLoading.then -> checkUserStatus.then -> getUserDetails

or is this not done at the component container level - is it better to take it to the FbActions level and import the necessary calls from UserActions there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2017-05-17
@uaKorona

Like, found a variant with thunk
It can dispatch function calls. It turned out something like:

fb.initCore().then(
      () => {
        dispatch({
          type: FB_LOADED_SUCCESS,
        });

        dispatch(getUserStatus());
      },
      () => {
        dispatch({
          type: FB_LOADED_FAIL,
        });
      },
    );

where getUserStatus is imported from UserActions.
Probably, it’s worth taking all this kitchen into middleware and combining it there, then the actions will become cleaner)

K
KnightForce, 2017-05-17
@KnightForce

Using thunk.
And inside you can use callbacks.

D
davidnum95, 2017-05-15
@davidnum95

For such cases, redux-saga is great.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question