Mutate with custom updater when no useSWR seems to have wrong state
See original GitHub issueBug report
Description / Observed Behavior
Simple case is:
- a user action that will trigger a mutate on a
key
with a custom updater - after this action is done mount a component (or in a next js app push to router) that will use this
key
-> the data that I see is not correct.
Expected Behavior
Expected behavior are:
- if mutate is call and then a first
useSWR
is done on the same key, we should expect correct data -> request is correctly done, but data does not seems to be use / drop
Repo Steps / Code Example
if you run this example: click on the button you will see that request is done -> but only the mutate data is use.
https://codesandbox.io/s/clever-knuth-2z40o?file=/src/App.js:1128-1161
Additional Context
0.3.9
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Mutation & Revalidation - SWR
The function passed to mutate will return an updated data which is used to update the corresponding cache value. If there is an...
Read more >SWR not re-rendering when mutate is called - Stack Overflow
Whenever the url provided to useSWR changes, it will refetch the data also giving you its loading state. You only have to create...
Read more >Data fetching in React and Next.js with useSWR to impress ...
Instead of fetching the data and storing it in state, we can store and update it directly in cache. This is where mutate...
Read more >Understanding state management in Next.js - LogRocket Blog
A state is a JavaScript object that holds the current status of the data. You can think of it as a light switch...
Read more >How to use the swr.mutate function in swr - Snyk
preventDefault() // mutate current data to optimistically update the UI // the fetch below could fail, in that case the UI will //...
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
No this is not what I want to see. Sorry if I didnt explain well. The behavior is:
What I expect is:
fake
Does the flow is clear now? Let me know If my explanation is correct
Thanks a lot for the fast investigation and fix !! You Rock 🥳