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
On the official document, I found two claims that seem to contradict each other:
If the resource is immutable, that will never change if we revalidate again, we can disable all kinds of automatic revalidations for it.
Since version 1.0, SWR provides a helper hook useSWRImmutable to mark the resource as immutable:
If a resource is immutable, why does useSWRImmutable still return a mutate function? There should not be a mutate function otherwise that is not really immutable, right?
The other statement seems to indicate a contradicting opinion that useSWRImmutable is simply a shorthand for useSWR without revalidation:
The revalidateIfStale controls if SWR should revalidate when it mounts and there is stale data. These 2 hooks above do the exact same thing. Once the data is cached, they will never request it again.
In reality, useSWRImmutable can be used to disable auto revalidation, its implementation seems to have nothing to do with immutable resources. One can use it for both mutable and immutable resources. It is implemented only as a shorthand for useSWR without revalidation. I do not see the first claim holds any ground and I feel the naming useSWRImmutable is a bit misleading since it has nothing to do with immutable resources. Anyone can help clarify?
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
On the official document, I found two claims that seem to contradict each other:
If a resource is immutable, why does
useSWRImmutable
still return amutate
function? There should not be amutate
function otherwise that is not really immutable, right?The other statement seems to indicate a contradicting opinion that
useSWRImmutable
is simply a shorthand foruseSWR
without revalidation:In reality,
useSWRImmutable
can be used to disable auto revalidation, its implementation seems to have nothing to do with immutable resources. One can use it for both mutable and immutable resources. It is implemented only as a shorthand for useSWR without revalidation. I do not see the first claim holds any ground and I feel the naminguseSWRImmutable
is a bit misleading since it has nothing to do with immutable resources. Anyone can help clarify?Beta Was this translation helpful? Give feedback.
All reactions