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

149
Vistas
Where to store Request promise before Abort in React project?

I want to cancel pending requests when the connection turns offline. To do that, I store all of my requests in my window.myRequests array. After the connection turns offline, I iterate the window.myRequests array and call item.abort() [I'm using superagent as a client] It works great. But I don't think that storing requests in window object is correct.

Where to store this array in a React application? Is the redux the correct address?

I want to make it accessible from anywhere in the component tree. Because I'm handling online/offline status in a single place.

Thanks in advance.

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

0

I think it's doesn't matter if u store it at a variable in global scope(window) or in local scopre(e.g,object, class instance), even redux.Only the difference between them is your code habit.I suggest u put the vars may cause page to render in redux.For better maintenance, u can make a class to store it, for example:

class RequestQueue {
    _queue = [];
  
    store(req) {
      this._queue.push(req);
    }

    remove(req) {
        const index = this._queue.findIndex(r => r === req);
        if (index > -1) {
            this._queue.splice(index, 1);
        }
    }

    /**
     * other functions:
     * ...
     */
}

const cache = new RequestQueue();
cache.store(...);
cache.remove(...);

// abort
cache._queue.forEach(req => abort(req))

If there is no problem with the function: abort, u could get what u want.

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