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

Conversation

haesoo-y
Copy link

@haesoo-y haesoo-y commented Feb 26, 2025

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.

If you prefer, I can change it to throw Error instead of a console error. Let me know if needed.

Required, but only if no default query function has been defined See Default Query Function for more information.
-TanStack Query React Docs-

Commit Result

image

(This Picture is @tanstack/query-example-react-nextjs)

Issue Situation

I was able to run my Next.js app without queryFn without any issues in Dev. However, when I built my Next.js app using useSuspenseQuery without queryFn, I encountered the following error.

Error: Missing queryFn:
image

(This Picture is @tanstack/query-example-react-nextjs)

The reason my Next.js app was able to run without queryFn or default queryFn was that I had already received the data on the Server-Side using HydrationBoundary( => initial data).

To prevent this situation, I have added a warning message.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant