A
A
alex4answ2020-12-28 09:27:35
React
alex4answ, 2020-12-28 09:27:35

Old and slow query overwrites result of new fast query in Redux, how to deal?

Good afternoon, I ran into the problem of "race requests".

1. There is a page where a list of houses is displayed (stored in redux), in which I make a request to get Statistics for these houses for the last 5 years (statistics are also stored in redux, but separately from houses)

2. There is a page for a detailed view of the house, there I am requesting statistics for a house for the last 7 days.

The problem manifests itself if you quickly go from the listing of houses to the detailed view page.
Due to the fact that the request for 5 years fulfills longer - it comes later than the one that takes statistics for 7 days.
And it overwrites the data, as a result, with fast transitions, the data is not relevant.

How to deal with this, what is usually done in such situations?
I am using redux-thunk

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-01-07
@Azurre

- In response, add the version/time of the request and discard the old one.
- On transition (componentWillUnmount) cancel the request ( https://github.com/axios/axios#cancellation )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question