Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(react-query): add warning when useBaseQuery is called without a queryFn #8701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export function useBaseQuery<
'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',
)
}
const defaultQueryFn = queryClient?.getDefaultOptions().queries?.queryFn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn’t enough because defaults can be defined on different “levels”.

the correct way is to check if there is a queryFn in defaultedOptions after line 62, where we do:

const defaultedOptions = client.defaultQueryOptions(options)

if (!options.queryFn && !defaultQueryFn) {
console.error(
'Error: queryFn is required, but only if no default query function has been defined. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function',
)
}
}

const client = useQueryClient(queryClient)
Expand Down