'react autocomplete how to stop first call and complete the second
I have an autocomplete form that receives a list, I would like that when I type in the search field every time I insert a letter the previous call is canceled and continues with the new call, I have tried with throttling but nothing to do ... I am using react with mui how could I do?
this is my function:
const myFunction= throttle(350, false, (value) => {
axios.get(url, {
params: {
q: value,
}
})
.then((response) => {
doSomething(response.data);
})
})
I would like to achieve this result

Thank you so much
Solution 1:[1]
Call the function when length of value is greater than equal to 2.
Solution 2:[2]
that's the diff between debounce and throttle
Try changing for debounce, you will complete at least one request in the bunch of events
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abhishek Badhan |
| Solution 2 | guiwme5 |
