Home > other >  react autocomplete how to stop first call and complete the second
react autocomplete how to stop first call and complete the second

Time:02-11

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);
  })
})

Thank you so much

CodePudding user response:

Call the function when length of value is greater than equal to 2.

CodePudding user response:

that's the diff between debounce and throttle

Try changing for debounce, you will complete at least one request in the bunch of events

  • Related