Replies: 2 comments
-
I believe the new proposal #992 is related to this, which we are working on. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've come up with this solution. It works, but I'd appreciate it any inputs to improve it. Basically I create the key in useSWR without any id so it's fixed and the the API will filter this empty request.
|
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
-
My use case is that I have a dropdown menu that fetches items from an API. It's a dependent fetching
const { data: projects } = useSWR(() => '/api/projects?id=' + projectId)
I'm experiencing these issues:
- I don't want to refetch something that is already in the cache (if the user fetches projectId 1, then 2, and then back to 1)
- But because the key changes, for each fetch it creates a new entry in the cache.
- Right now the fetch at the useSWR is not conditional; every time is fetching something regardless of being cache or not.
How can I implement it?
- How can I say useSWR to fetch something depending on whether it is already in cache or not? (conditional fetched based on cache)
- Can it be done with only one cache?
I've seen these two posts from @sergiodxa and I've got some ideas but I'm not sure how to implement it:
#525 (comment)
#360
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions