0

I have to compose several API requests, I am using redux.

For the sake of simplicity let's say there are 2.

When I obtain the response from request A, I use response.data.param, and make request B.

Should this be done where I make the API requests, making

requestA .then(res => requestB(res.data.param)) 

Or in the component where I dispatch the actions?

dispatch(A()) .then(res => dispatch(B(res.data.param))) 

or in the actions?

Thank you in advance

1 Answer 1

1

It depends totally on the use case. If your UI is reflecting the response of request A, while B is loading, it is better to dispatch on component, e.g. some progress level. If UI depends on both, then it is better to call them just one after another in reducer only.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, no, I will not show the response of A, A only gets called to get the parameters for B, if I do not need B, I do not need to call A either, so should I concatenate on making the requests or in the actions?
Then those are inherently bound to single logic and you can call them in chain. That way you dont have to write two reducers as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.