'Predicting server-side data with React Query
Imagine I was writing an application that fetches how many units of a resource are currently available and its (static) hourly production via an API call. Knowing those numbers I'd like to predict the current value of resources every second without polling the server itself. This should be more or less deterministic until I receive a message, for example via a WebSocket, that something has changed. Since I want to reuse that amount of resources across different components I thought of the following implementation:
First have a query that fetches a snapshot of the current amount of resources, its production and the timestamp of the snapshot. Then create a query similar to the example in the docs that has a refetch interval and does not fire an API call but instead updates the predicted amount of resources at the time of invocation.
Any suggestions on whether there is even better solutions to that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
