Pass multiple arguments to global fetcher #2676
-
Hello 👋🏽 <SWRConfig value={ {
fetcher: () => fetchEntities(entitiesId, endpoint)
} }> Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
StyleShit
Jun 19, 2023
Replies: 1 comment
-
When you need to pass multiple arguments to the fetcher, you need to make sure that the key also gets changed based on those arguments or the cache key will be wrong and you'll get invalid/stale data. You can simply construct the cache key as an object with all of the dependencies of the fetcher: https://swr.vercel.app/docs/arguments.en-US#multiple-arguments |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
IdoBouskila
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you need to pass multiple arguments to the fetcher, you need to make sure that the key also gets changed based on those arguments or the cache key will be wrong and you'll get invalid/stale data.
You can simply construct the cache key as an object with all of the dependencies of the fetcher:
https://swr.vercel.app/docs/arguments.en-US#multiple-arguments