Replies: 1 comment
-
Try using this way, so you can make sure the swr will get from the cache instead const { data, mutate } = useSWR( |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello SWR gurus,
Anybody have ideas about how to handle this scenario? Say I have some arbitrary text post component
which uses SWR to display the post data and conditionally renders an edit component (controlled by
isEditing
) for that text:Upon submission of the user's input, we call mutate with local data (and revalidation disabled), then set
isEditing
tofalse
, and expect the "post" to display that new data sent tomutate
. The issue is that mutate does update the cache, but changingisEditing
causes a re-render, which then causes the original SWR call to revalidate. If the API has not yet updated with the new data (maybe it's a slow server), then it will revalidate with the old data, undoing the local datamutate
.Any ideas about how you might approach this scenario? Am I missing something about the
shouldRevalidate
option inmutate
?Beta Was this translation helpful? Give feedback.
All reactions