You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use SWR with a globally configured axios fetcher like this
<SWRConfigvalue={{fetcher: getFetcher,}}> ...
I don't want to refetch on every component mount, so I have disabled revalidateIfStale. So far so good.
I sometimes want to revalidate a key (get fresh data in the background without a loading-state) and for this I can use mutate from the useSWR-hook or even just import mutate directly from SWR. So far so good.
Now the problem is when the resource in question is loaded at some point, but not currently mounted. mutate then does nothing, which technically makes sense because it probably doesn't know what to do, but from how I want it to work it really sucks that I as a developer have to know whether a certain resource is currently mounted or not to be able to choose the right method of invalidating the cache.
How can I have SWR cache stuff without revalidating on every single mount while still having one simple way of invalidating resources?
I realize it sounds like I want invalidateIfStale to be true, and I maybe I do. But I don't want resources to be fetched on every mount.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I use SWR with a globally configured axios fetcher like this
I don't want to refetch on every component mount, so I have disabled
revalidateIfStale
. So far so good.I sometimes want to revalidate a key (get fresh data in the background without a loading-state) and for this I can use
mutate
from theuseSWR
-hook or even just importmutate
directly from SWR. So far so good.Now the problem is when the resource in question is loaded at some point, but not currently mounted.
mutate
then does nothing, which technically makes sense because it probably doesn't know what to do, but from how I want it to work it really sucks that I as a developer have to know whether a certain resource is currently mounted or not to be able to choose the right method of invalidating the cache.How can I have SWR cache stuff without revalidating on every single mount while still having one simple way of invalidating resources?
I realize it sounds like I want
invalidateIfStale
to be true, and I maybe I do. But I don't want resources to be fetched on every mount.What are my options?
Thanks 🙏
Beta Was this translation helpful? Give feedback.
All reactions