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

77
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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