Why does useQuery
need a key? Is it possible to do without it?
#353
Unanswered
bitttttten
asked this question in
General
Replies: 2 comments 1 reply
-
Yep, you can easily do this like you have shown in a custom hook that wraps useQuery, or you could even experiment with the custom key serializers as well. The reason it's built this way is so that is can be flexible enough to handle use cases just like this one. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Oh nice! Yeah, I can see this easily being added in then :) Are there any downsides to doing is this way? Are there any edge cases that are avoided or solved by using the string keys as in the docs? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been wondering why does
useQuery
actually need a key that the user needs to create? I was thinking it would be possible to make a "hash map" where the caches can be keyed by thequeryFn
. Would there be any issues with that? With a Map data structure, you are able to use a function as a key.I was imaginging a cache implementation of:
I was trying to check out the code and couldn't see any cases where the key sent from the user is needed.. although I am still digging through! And I feel like it would make such a great improvement to the API 🤔
Beta Was this translation helpful? Give feedback.
All reactions