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

152
Views
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 answers
Answer question

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