Allow useShopQuery
to be disabled via options
#1948
davidhousedev
started this conversation in
Ideas + Feature Requests
Replies: 1 comment 5 replies
-
It's not very clear in the docs, but you can conditionally not call Does this help, or are you looking for something different? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As we've built more components that use
useShopQuery
, we've encountered some situations where we want to invoke the query conditionally. Currently, that's very challenging inuseShopQuery
without breaking the rules of hooks. React Query gets around this by exposing anenabled
option on their queries which allow the hook to be called but not run. As a result, they also return astatus
in the return type.We can get around this in
useQuery
by rejecting the promise early in the query function, but we're having a tougher time withuseShopQuery
. That said, disabling auseQuery
is non-trivial. One option is to return aPromise.reject
from the query function,but this will log an expected behavior as an error from within. The other option is to have the function return a type union, but the typings foruseQuery
useQuery
expect that the query function only returns one interface so you need to dip into generic typing onuseQuery
.Edit: My mistake! I was misinterpreting what I was seeing in my terminal.
Beta Was this translation helpful? Give feedback.
All reactions