Canceling previous pending request in React (Apollo client with useQuery)

Viewed 396

I have on search page where we have search box so when typing continue then it is sending multiple requests for each type. I used debounce to handle this so my request is reduced but now I need to cancel the request which is pending and only the latest should be there

I tried a few methods but it is not working for me.

Apollo client Version - 3.3.21 React version - 17.0.2 React-dom version - 17.0.2 Node - 16

The method which I tried

1 Answers

You can implement a debounce on the query itself by using a similar technique as described here. I used it to cancel page fetches in cases of "over zealous" navigation between pages. Works like a charm.

Related