Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

274
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda