Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to handle asynchronous call in redux react application

I am beginner of react application. I need handle asynchronous call in my application.

For the implement asynchronous call is there any library for that ?

How to implement asynchronous call using library ?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

For the implement asynchronous call you can use following library with react-redux

  1. redux-thunk
  2. redux-promise
  3. redux-saga

You can learn asynchronous call handling using library documentation

over 4 years ago · Santiago Trujillo Report

0

If you are using vanilla ReactJS and your App does not need any Flux or Redux to control the state of the App, you can use React life-cycle method componentWillMount for that with builtin fetch method or library like axios

If your Application needs Flux or Redux then I personally recommend Redux over Flux and you can use redux-thunk middleware for that. for example

const INCREMENT_COUNTER = 'INCREMENT_COUNTER';

function increment() {
  return {
    type: INCREMENT_COUNTER
  };
}

function incrementAsync() {
  return dispatch => {
    setTimeout(() => {
      // Yay! Can invoke sync or async actions with `dispatch`
      dispatch(increment());
    }, 1000);
  };
}

For more see http://redux.js.org/docs/advanced/AsyncActions.html

over 4 years ago · Santiago Trujillo Report

0

Here is the documentation for how to use async actions : http://redux.js.org/docs/advanced/AsyncActions.html

You define it like so when configuring the store:

const store = createStore(
  rootReducer,
  applyMiddleware(
    thunkMiddleware
  )
)

And you use it in the actions like so:

function fetchAction(data) {
  // Return a function, this function will be activated the the thunk middleware with dispatch as parameter
  return function (dispatch) {
    // Dispatch some action before fetch (like setting loading)
    dispatch(requestData(data));

    // return a promise of the fetch
    return fetch('yoururl')
      .then(response => response.json())
      .then(json =>
        // dispatch a new action when you get your data
        dispatch(receivedData(data,json))
      ).catch (e = > 
        // you can also dispatch an error
        dispatch(errorData(data,e));
      )

  }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!