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

275
Visualizações
Async call using redux thunk
    const fetchUsersRequest = () => {
      return {
        type: FETCH_USERS_REQUEST,
        info: {
          loading: true
        }
      };
    };
    
    const fetchUsersSuccess = (data) => {
      return {
        type: FETCH_USERS_SUCCESS,
        info: {
          loading: false,
          users: data,
          error: null
        }
      };
    };
    
    const fetchUsersError = (error) => {
      return {
        type: FETCH_USERS_ERROR,
        info: {
          loading: false,
          users: null,
          error: error
        }
      };
    };
    
    const fetchData = () => {
      return (dispatch) => {
        dispatch(fetchUsersRequest());
        axios
          .get("https://jsonplaceholder.typicode.com/users")
          .then((res) => {
            dispatch(fetchUsersSuccess(res.data));
          })
          .catch((err) => {
            dispatch(fetchUsersError(err));
          });
      };
    };
  const requestReducer = (response = {}, action) => {
      if (
        action.type === FETCH_USERS_REQUEST ||
        action.type === FETCH_USERS_SUCCESS ||
        action.type === FETCH_USERS_ERROR
      ) {
        response = { ...action.info };
        return response;
      }
      return response;
    };
    
    const store = createStore(requestReducer, applyMiddleware(thunk, logger));
    
    store.dispatch(fetchData());

The calls to dispatch in axios.then() and axios.catch() never get executed. Even though I am getting the data in the response and the same data gets console logged but the actions are not getting dispatched. The state always has {loading:true} and the result from api call is not updating the state.

about 4 years ago · Juan Pablo Isaza
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