mutate() and the deduping interval
See original GitHub issueBug report
Description / Observed Behavior
I prefetch and mutate some data when the user hovers a link using mutate(key, data, false)
When the user clicks the link, the page is loaded and useSWR revalidates the data.
However, the hover and the click where made within deduping interval.
Expected Behavior
Do not revalidate if mutate(key, data, false)
has been called within the deduping interval
Repro Steps / Code Example
export async function prefetch(){
mutate("/api/data", () => fetcher("/api/data"), false)
}
export function DataPage(){
const res = useSWR("/api/data", fetcher) // will revalidate even though mutate has been called withing the deduping interval
return <>
...
</>
}
Additional Context
swr@1.0.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
API
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >swr/README.md
97, const { data, error, isValidating, mutate } = useSWR(key, fetcher, options) ... 125, - `dedupingInterval = 2000`: dedupe requests with the same...
Read more >Can I fetch data only once when using swr?
If you need more time just increase the deduping interval. const { data, error } = useSWR('/api/get.json', fetcher, { dedupingInterval: ...
Read more >Sswr NPM | npm.io
:+1: Optimistic UI / Manual mutation of the data by using mutate() . ... dedupingInterval: number = 2000 : Determines the deduping interval....
Read more >Intelligent fetching and caching with SWR - Bekk Christmas
✨ Getting the data · ...where is the cache and the strategy? · ☢️ Mutation · ⛔️ Deduplication · ♻️ Automatic retries ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For those who don’t want to scratch their heads anymore, wondering why the fuck swr does this, I made my own library.
https://github.com/hazae41/xswr
It uses composition-based hooks and has a very easy learning curve, and 0% weird behaviour.
I tried and it doesn’t revalidate, but I want it to revalidate if the stale data is older than the deduping interval