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

137
Views
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
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!