question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

global mutate can't revalidate useSWRInfinite data

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
shudingcommented, Nov 25, 2021

We should add this to the docs, but there is currently a bug in Nextra blocking this…

1reaction
huozhicommented, Mar 7, 2022

@ezeikel Good point! I opened https://github.com/vercel/swr-site/issues/264 for this doc requirement

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found