global mutate can't revalidate useSWRInfinite data
See original GitHub issueBug report
Description / Observed Behavior
What kind of issues did you encounter with SWR?
For example a Todo app, on the list page:
I using useSWRInfinite
to load todos, the first page’s key is /api/todos
,
Then I delete a Todo (send request to backend to deleted it), and I need revalidate the data:
If I use mutate
returned from the useSWRInfinite
call, it will work.
If I use mutate
from const { mutate } = useSWRConfig()
, it will not work.
Expected Behavior
How did you expect SWR to behave here?
Both way need way. because I may call the delete not on the same component, so I can’t pass the mutate function to other component
Repro Steps / Code Example
Additional Context
SWR version. 1.0.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Mutation & Revalidation - SWR
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 >useSWRInfinite with pagination and mutate features
The data from useSWRInfinite should be updated right away since I am ... set revalidate option to true but an async function in...
Read more >SWR v1 is here: What's new? - LogRocket Blog
In a nutshell, the stale-while-revalidate strategy simply means serving or returning the stale (cached) data while you revalidate (fetch) ...
Read more >How to scale data fetching with SWR | by BOOM - Medium
The acronym SWR stands for Stale-While-Revalidate: a pattern used in ... useSWR hook, which also provides mutation function, to force data reload. the...
Read more >swr: Versions | Openbase
You can now pass a filter function to the global mutate API to match any keys ... This means that you can't use...
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
We should add this to the docs, but there is currently a bug in Nextra blocking this…
@ezeikel Good point! I opened https://github.com/vercel/swr-site/issues/264 for this doc requirement