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

249
Vistas
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 Respuestas
Responde la pregunta

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