You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are surveying using swr as our data-fetching technology (so far it looks amazing).
Even after reading the documentation, we still had some questions.
We know the answers for the questions below (it is easy to run a quick experiment to get the answers), but possibly the documentation can be updated to prevent us having to run experiments.
// conditionally fetchconst{ data }=useSWR(shouldFetch ? '/api/data' : null,fetcher)
Our case:
constshouldFetch=!doNotDisturb;// User can toggle this at will (this is fictional condition, but demonstrate something that can change dynamically).const{ data }=useSWR(shouldFetch ? '/api/data' : null,fetcher,{refreshInterval: MINUTE});
Question is: If shouldFetch toggles from true to false, polling will stop right (and then restart when it toggles back to true)?
dedupingInterval
Our use case is this:
We want to poll every minute.
Other than polling we always want to dedup (there could be multiple requests by the user that will have the same swr key - we want them all served from cache).
Will it poll after 5 minutes (or will the dedupe serve from cache)?
If there is a poll after 5 minutes, and the user trigger a request after 7 minutes that is already cached, will dedupe kick in (or does it reset with polling).
On a separate note, we found the term dedupingInterval a bit confusing. Dedupe typically means removing duplicate items from a list. Maybe from an implementation point of view this is what's happening. But for users, why not just call it cacheInterval?
There's farther confusion between the caching and deep-compare - if either the cache is served or the returned value is the same, data will not be mutated. Which does dedupingInterval control?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We are surveying using
swr
as our data-fetching technology (so far it looks amazing).Even after reading the documentation, we still had some questions.
We know the answers for the questions below (it is easy to run a quick experiment to get the answers), but possibly the documentation can be updated to prevent us having to run experiments.
Conditional Fetching
The docs give this example:
Our case:
Question is: If
shouldFetch
toggles fromtrue
tofalse
, polling will stop right (and then restart when it toggles back totrue
)?dedupingInterval
Our use case is this:
We are not sure how these two interact.
Say our configuration is like so:
Question are:
On a separate note, we found the term
dedupingInterval
a bit confusing. Dedupe typically means removing duplicate items from a list. Maybe from an implementation point of view this is what's happening. But for users, why not just call itcacheInterval
?There's farther confusion between the caching and deep-compare - if either the cache is served or the returned value is the same,
data
will not be mutated. Which doesdedupingInterval
control?Beta Was this translation helpful? Give feedback.
All reactions