Replies: 1 comment 19 replies
-
some time ago, react-query had nullable query keys, but I think with v2 or so, this was changed to the
|
Beta Was this translation helpful? Give feedback.
19 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I use SWR and I'm considering switching to React Query. Basically everything about react-query seems better so far, except one: null / error keys.
With SWR, you can do this:
With react-query, it seems like you have to just use the
enabled
prop. However, this does not exactly serve the same function. I want to use a nullable key so that I can keep my typescript types strict.This is how my code usually looks (illustrative)
I want to ensure that my
key
has a strict type. Otherwise, I would have to manually setenabled: false
and check the conditions of the key. But the conditions can change (it might depend on more than simplyuser.id
in the future.)With the method described above, I can use the
ReturnType
of myqueryKey
in myqueryFn
.It also allows for a
queryKey
to be a function, and if that function throws, the query doesn't fire. This is really useful in many cases as well.Beta Was this translation helpful? Give feedback.
All reactions