T
TanStack3y ago
compatible-crimson

client.defaultQueryOption is not a function

Error = Uncaught TypeError: client.defaultQueryOptions is not a function
No description
No description
No description
12 Replies
equal-aqua
equal-aqua3y ago
You're mixing v4 (devtools?) with v5
rival-black
rival-black3y ago
I had this error too, no time to create an issue … the problem is due to a bad call of useQuery, not using the object form. When not using TS we (poor devs) do not have feedback. What about throwing a dedicated error for this one? More precisely we should be able to detect the bad client before
equal-aqua
equal-aqua3y ago
yeah, I think this is just the first thing that errors. What I would do is add a check in useQuery that logs a descriptive error if useQuery is called with more than one argument or if the first arg isn't an object, in non-prod builds. we already have some checks, e.g. here: https://github.com/TanStack/query/blob/35539bf34f4e623c9ad70bbcd3d01e1f837bfa63/packages/query-core/src/query.ts#L474-L478
GitHub
query/packages/query-core/src/query.ts at 35539bf34f4e623c9ad70bbcd...
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. - TanStack/query
equal-aqua
equal-aqua3y ago
please contribute this if you want 🙂
rival-black
rival-black3y ago
On my side it would be more « if I have time » From what I encountered this is also true for fetchQuery and other client methods Will try to have a look, no guarantee on timing though
compatible-crimson
compatible-crimsonOP3y ago
I found solution
No description
rival-black
rival-black3y ago
Yep starting v5, this is the only supported syntax. @TkDodo 🔮 I had some times to look after this today. I have 2 ideas to help with this. Would like some feedback about them if you have time. 1- add a check on options in useBaseQuery to make sure it is an Object. Error if not. 2- add a check on the type of queryClient passed to useQueryClient. This is the culprit in the error above. Due to the change in useQuery signature, the queryOptions are passed as 3rd param of useBaseQuery <=> queryClient. It is then passed to useQueryClient which returns it if defined. I can submit a PR with the 2 proposals above to discuss. Thx
rival-black
rival-black3y ago
1st idea
No description
rival-black
rival-black3y ago
2nd idea
No description
equal-aqua
equal-aqua3y ago
1st idea looks good 👍
rival-black
rival-black3y ago
Available in latest version Starting v5.7.0

Did you find this page helpful?