How to structure a redux-saga to handle parallel API calls

0 votes
With the help of code can i know How to structure a redux-saga to handle parallel API calls?
6 days ago in Node-js by Ashutosh
• 22,830 points
31 views

1 answer to this question.

0 votes

You can use the all effect, which allows multiple sagas or API calls to run concurrently and wait for all of them to complete.

Let's see to structure a redux-saga for parallel API calls:

import { all, call, put } from 'redux-saga/effects';

import { fetchData1, fetchData2 } from './api'; 

function* fetchParallelDataSaga() {

  try {

    const [response1, response2] = yield all([

      call(fetchData1),

      call(fetchData2)

    ]);

    yield put({ type: 'FETCH_PARALLEL_SUCCESS', payload: { response1, response2 } });

  } catch (error) {

    yield put({ type: 'FETCH_PARALLEL_FAILURE', error });

  }

}

answered 1 day ago by anonymous

Related Questions In Node-js

0 votes
1 answer
0 votes
0 answers

How to manage async API calls in a React app using redux-thunk?

Can you tell me How to manage ...READ MORE

6 days ago in Node-js by Ashutosh
• 22,830 points
24 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to differentiate between takeLatest and takeEvery in redux-saga?

Feature takeEvery takeLatest Execution Behavior Executes every triggered action. Executes only the ...READ MORE

answered 1 day ago in Node-js by anonymous
32 views
0 votes
1 answer

How to integrate redux-saga middleware into a React project?

To integrate redux-saga middleware into a React ...READ MORE

answered 1 day ago in Node-js by anonymous
31 views
0 votes
1 answer
0 votes
1 answer

How to structure major sections of a redux-saga implementation?

To update Redux state in response to ...READ MORE

answered 6 days ago in Node-js by Tanvi
46 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP