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

239
Views
Cancel subsequent axios api calls, keep the last

I have a text input which value most be unique, to ensure that, I make an API call every time the input changes its value, giving a instantly feedback to the user of whether the input is valid or not.

There are 2 problems with this aproach:

1- Too many innecesary API calls.

2- When the user types fast enought there is a chance that responses came out of order.

For example: If type "foo bar" there will be 7 request checking for: "f","fo","foo","foo ","foo b","foo ba","foo bar" in that exact order. Lets say if "foo ba" is valid but "foo bar" is NOT. If typing is relativly slow it will be ok but if it is fast enough can happend that response from "foo ba" is returned last, meaning the state will be "valid" when it is not

Posible solution will be that any api call cancels all previus calls in progress.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think your hunch that doing a call for every character being wrong is correct. You really should either verify on post that the entry is unique, and if not tell the user. If you want more real time feedback, you could send all the current entries from your DB once on page load, and loop through that on the front end (still not a great solution)

if you are married to your idea, you could solve it as follows:

Generate a unique id for each call and include it in your request.
when you make the call, save that id to a variable, something like lastCall. Every call you make will update the id of last call. Then, when you start getting responses, you only need to react to responses that contain the same id that its in lastCall.

Again, I would recommend changing your approach, but this solution will help fix the issue of calls coming in out of sync. You will still be spamming your backend though.

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!