Skip to content

Commit

Permalink
chore(react-query): add warning when useBaseQuery is called without a…
Browse files Browse the repository at this point in the history
… queryFn

Added a console error in development mode when useBaseQuery is called without a queryFn or default queryFn.
This helps developers avoid potential issues by ensuring at least one of them is provided.
  • Loading branch information
haesoo-y committed Feb 26, 2025
1 parent 74db582 commit ba37b6a
Showing 1 changed file with 6 additions and 0 deletions.
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
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

0 comments on commit ba37b6a

Please sign in to comment.