Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda