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

110
Vistas
Request HTTP every 1 sec and update state with the incoming object from the response delays the application

I need to request an endpoint every 1 sec and with that response (around 30 array) update React context state and the ui. It's working but at some point it got so slow and chrome start behaving weird. What is the best way to solve this? with some library like lodash?

Hook/context state:

const [stateData, setStateData] = useState(null);

The following method is the one that triggers every X sec, where X can be [1,10,15,20] seconds

  const subscribeOb = async (): Promise<void> => {
    await m?.subscribe((event) => {
     getData()
   });
  };

This method is the one that its called once the subscription triggered

  const getData = async (): Promise<void> => {
  try {
   const { a, b } = await generalObj?.data();
   const currentA = (stateData?.asks as Data[]) || [];
   const currentB = (stateData?.bids as Data[]) || [];
   const newObj = {
     asks: [...a, ...currentA],
     bids: [...b, ...currentB],
   };
   setStateData(newObj); // this is from the hook in the context
  } catch (e) {
  console.log("Error found while getting Data", e);
  }
};
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