A hook for fetching data where only the response from the most recent fetch request is needed.
When the arguments are updated, a new fetch request is triggered and the previous one is aborted and ignored.
This is useful in situations where a user might make selections in the UI that trigger multiple fetch requests. For example, selecting from a group of filters which then fetches new data from an API. In this situation, only the most recent selection is relevant.
const { data, error, loading } = useMostRecentFetch('https://example.com/api', {
method: 'POST',
body: JSON.stringify({ filter1: 'value', filter2: 'value' })
})