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
In this example, three hooks are called, and each hook request data because they can not find cached data.
I have found how key argument is cached in useSWR. In the key hash function, class instances are not allowed by default.
I tried to add custom hash functions for specific objects. stableHash converts key arguments to string to identify caches.
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
-
In
useSWR
, if complex objects are inkey
, caching behavior do not work like what I expected.In this example, three hooks are called. The first hooks is able to cache response, so second, and third hooks do not need to request data.
In this example, three hooks are called, and each hook request data because they can not find cached data.
I have found how key argument is cached in
useSWR
. In the key hash function, class instances are not allowed by default.I tried to add custom hash functions for specific objects.
stableHash
converts key arguments to string to identify caches.The custom hash function can be injected by swr configs.
With custom hash functions, class instances could be cached like string, number, boolean.
Now I am working with this custom hash feature.
Can I suggest this discussion?
Beta Was this translation helpful? Give feedback.
All reactions