Replies: 1 comment
-
No solution yet, (but again then SWR generates more cache entries using different queries as keys) |
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
-
Currently using composite key and this is the resulting cache when run with different query parameters:
I am using a composite key:
const { data, mutate } = useSWRImmutable<IPosition[]>([NEW_SITE_API.POSITIONS, queryString]);
Maybe I don't understand but this seems like a huge memory problem in the long term, since the cache will also live forever.
So how do you pass query params to the fetcher? I have tried:
let cachedQueryString = '';
export const usePositions = (queryString: string) => {
const { data, mutate } = useSWRImmutable<IPosition[]>(NEW_SITE_API.POSITIONS,
{
fetcher: (url) => getPositions(url + queryString),
errorRetryCount: 0,
}
);
if(queryString !== cachedQueryString) mutate();
return { data, mutate };
};
You can't do this because once the hook won't pass new instances of queryString to the fetcher, basically the same fetcher function with the same parameters will always run
Beta Was this translation helpful? Give feedback.
All reactions