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
skipTokenin my project for type-safety. It's a large project with dozens ofuseQueryanduseInfiniteQueryhooks. We have light wrappers arounduseQueryto ensure consistency with query keys and URLs, but otherwise the wrapper accepts aUseQueryOptionsobject:If someone passes in
{ enabled: true }without defining theid, we get a"Missing queryFn"error. According to @TkDodo in #7057,enabledandskipTokendon't go together, so this error is expected.However, I thought that this would work:
In theory,
enabledshould never be true unless theidis also defined, no matter whatoptionsare passed in from the outside. But I was still able to getuseQueryto 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: 1andenabled: true,useQuerycallsqueryFnwhich fetches the member 👍enabledtofalseso it stops fetching 👍idto0which means thatqueryFnshould now have the valueskipTokenenabled: trueAs far as I understand things, this should not result in a fetch because
idis still falsy—useQueryshould receiveenabled: falseandqueryFn: skipTokenbased on the code. However, as you can see in the video, a request is made usingid: 0which 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
skipTokenthat still allows for a component to pass in theenabledoption?Beta Was this translation helpful? Give feedback.
All reactions