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

138
Vistas
Need help resolving a promise and assigning the returned values

I'm trying to pass the formatted (JSON) API results into the redux store. I'm able to retrieve the data and resolve the promise but I can't assign the returned data inside the '.then' method.

Can you please tell me what I'm doing wrong? Also I'm newer so please be kind if I mistake a question. Thank you.

Reducer

import apiTest from "../api/ApiTest";

const initialState = {
  listData: null
};

const contactListReducer = (state = initialState, action) => {
  switch (action.type) {
    case "FETCH":
      console.log("inside switch (reducer) ");
      return getData(state);
    default:
      return state;
  }
};

const getData = (state, action) => {
  console.log("Inside getData");
  let data;
  let request = apiTest().then((results) => {
    data = results;
    console.log("INSIDE THEN");
    console.log(data);
  });
  console.log("OUTISIDE THEN");
  console.log(request);
  return Object.assign({}, state, {
    listData: request
  });
};

export default contactListReducer;

API Code:

import React, { useEffect, useState } from "react";
import axios from "axios";

const apiCall = async () => {
  try {
    const payload = await fetch("https://jsonplaceholder.typicode.com/users");
    const results = await payload.json();
    // console.log(results);
    return results;
  } catch (err) {
    console.log(`error found of type ${err}`);
  }
};

export default apiCall;


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