I'm trying to implement a search box, where every time user types something, the search result will show on the page. JS fiddle link : https://jsfiddle.net/wsypeter/dh59Lwr2/47/
here is the code for fetching the data and setting the state
basically as I type abc
the response might came back in order abc
ab
a
and the result is finally a
which is wrong.
How should I fix this ? I know one way is to use debounce, but I think it will still run into issue if the response timeout is super long.
This is an interview question, the interviewer said canceling pending request or debouncing is not the solution he's looking for. For the above example , there must be 3 requests going out and the final result should be the response of the last request. How do I do it?