Replies: 1 comment
-
Because your fetcher is not stored outside each individual usage of SWR, the only way to trigger a revalidation (call mutate with only the key) is when there is a component mounted using the same key you are revalidating. Note that once a component using that key is mounted again it will automatically revalidate it even if you don’t call mutate (it will however render with the old cached data first). You can, however call mutate with a key, and a new value or a promise resolving to the new value or a function returning a promise with the new value (this function will receive the current value as argument), this way even if there are no components using that key the cached data will be updated and used the next time it is required by a component. |
Beta Was this translation helpful? Give feedback.
-
Didn't find it in docs or maybe its a bug, but is it possible to mutate data when component is already unmounted?
As common example user submits data in a component, then (immediately) navigates away/back to a different component
When user returns to component form values (inputs) are being initially populated with stale default values and are not affected with later revalidation changes.
I'm curious how others handle this pattern?
Beta Was this translation helpful? Give feedback.
All reactions