I have created a pagination component including the previous and next buttons on either side of the page numbers.
Every time they press a button on the pagination component (e.g. an available page number, next, or previous), I subscribe to a function in my service that makes a GET request to an API.
This works as expected, however if the user was to spam press any of the buttons, it hits the API multiple times. Considering that subscribing to the HTTP request is an async function, the data that gets returned may not be the latest data the person requested.
Basically if the user hits the button 6 times, but request 5 may have taken longer to retrieve data then request 6, so when it comes to populating my object it gets overwritten with request 5's data, which is not ideal.
I could disable the pagination whilst waiting for a request however this may crop up at another time and I want to be prepared for that inevitability.
What is the best way to handle this?