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

129
Vistas
Variables updated in fetch method don't retain in state
  const searchCacheFlightHotelsPackage = () => {
setValues({ ...values, loading: true });
let result = null;
getCacheFlightHotelsPackage() //returns a promise
    .then((data) => {
      if (data.list.length > 0) {
        result = paginate(data.list);
        hotelFlightPackageList = data.list;
      } else {
        console.log("sorry no packages found========");
      }
      console.log(hotelFlightPackageList);
      setValues({ ...values, loading: false });
    })
    .catch((e) => {
      console.log("packages data error=======", e);
      setValues({ ...values, loading: false });
    });

I have variables outside this function like let hotelFlightPackageList = []; which updates in the method but once outside the method it's back to being an empty array. I have also tried using setValues which you can see an example of with the loading setting to false. I wish I could just update the global state in fetch but It gives a react hook error when doing that.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Turns out you can update the global state in fetch once you make the global state variable a const outside of the fetch! Working now!

about 4 years ago · Juan Pablo Isaza 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