Replies: 1 comment
-
My mistake, I had an error in my demo code. I was passing the ID as a string, so |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This might be related to #5916 but I think the question is slightly different.
I'd like to use
skipToken
in my project for type-safety. It's a large project with dozens ofuseQuery
anduseInfiniteQuery
hooks. We have light wrappers arounduseQuery
to ensure consistency with query keys and URLs, but otherwise the wrapper accepts aUseQueryOptions
object:If someone passes in
{ enabled: true }
without defining theid
, we get a"Missing queryFn"
error. According to @TkDodo in #7057,enabled
andskipToken
don't go together, so this error is expected.However, I thought that this would work:
In theory,
enabled
should never be true unless theid
is also defined, no matter whatoptions
are passed in from the outside. But I was still able to getuseQuery
to perform a fetch with a badid
:CleanShot.2024-03-22.at.10.21.16.mp4
This is the basic order of events in the video:
id: 1
andenabled: true
,useQuery
callsqueryFn
which fetches the member 👍enabled
tofalse
so it stops fetching 👍id
to0
which means thatqueryFn
should now have the valueskipToken
enabled: true
As far as I understand things, this should not result in a fetch because
id
is still falsy—useQuery
should receiveenabled: false
andqueryFn: skipToken
based on the code. However, as you can see in the video, a request is made usingid: 0
which fails with a 404.How is it fetching when
id = 0
? Is it caching a previous value ofqueryFn
?Code sandbox
Is there a way to use
skipToken
that still allows for a component to pass in theenabled
option?Beta Was this translation helpful? Give feedback.
All reactions