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

75
Views
React jsonserver promise result issue

I am creating a react/ redux app with json fake api server I am trying to add a login and trying to get data from json fake api server, data is showing and all ok , but data is always resulting as a promise and the required data is inside the promise. i tried many ways to distructure but throwing errors , could anyone help me on this,

my axios request


const urlss = "http://localhost:5000/users";

    export const userslist = async () => {
      const r = await axios.get(urlss);
      const data = r.data;
    
      return data;
    };
    const newout2 = userslist();
    const newout = newout2;
    console.log(newout);

the place where I am using it


   export const login = (credentials) => (dispatch) => {
  return new Promise((resolve, reject) => {
    const matchingUser =
      newout2 &&
      newout2.find(({ username }) => username === credentials.username);
    if (matchingUser) {
      if (matchingUser.password === credentials.password) {
        dispatch(setUser(matchingUser));
        resolve(matchingUser);
      } else {
        dispatch(setUser(null));
        reject("Password wrong");
      }
    } else {
      dispatch(setUser(null));
      reject("No user matching");
    }
  });
};

i am getting this error

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are using then in your userslist method while awaiting in an async method. drop the then and just use proper await inside an async method.

const urlss = "http://localhost:5000/users";
export const userslist = async () => {
  const r = await axios.get(urlss);
  const data = r.data;

  return data;
};
about 4 years ago · Santiago Trujillo Report
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!