Skip to content
Advertisement

Struggle with chaining of promises in react application

JavaScript, React – sending multiple simultaneous ajax calls struggling with promises. Basically I want to chain the calls, if one server call completes then only do next call, and collect the successful response of calls from endpoint /pqr made inside makeServerCalls.

JavaScript

Error: expected to return a value in arrow function. What am I doing wrong here?

Is this a right chaining or it can be optimized?

What happens if some call fails in between?

Advertisement

Answer

You can use Async library for this. No need to re-invent the wheel.

There is a waterfall function that takes a list of functions that execute in series. You can pass result of function 1 to function 2 to function 3 and so on. Once complete waterfall executes, you get the result in callback. You can read more about it in the docs in the link above.

Advertisement