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.