Skip to content

chore(react-query): add warning when useSuspenseQuery is used without queryFn#8700

Closed
haesoo-y wants to merge 1 commit intoTanStack:mainfrom
haesoo-y:chore/warning-suspense-queryfn
Closed

chore(react-query): add warning when useSuspenseQuery is used without queryFn#8700
haesoo-y wants to merge 1 commit intoTanStack:mainfrom
haesoo-y:chore/warning-suspense-queryfn

Conversation

@haesoo-y
Copy link
Copy Markdown
Contributor

useSuspenseQuery is designed to accept queryFn as an optional parameter. (related #8176)

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 initialData was that I had already received the data on the Server-Side using HydrationBoundary.

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

Alternatively, this could be addressed by modifying the implementation like the example below, but I don’t think this would be the best approach:

initialData: options.initialData ?? queryClient?.getQueryData(options.queryKey),

… queryFn

Added a console warning in development mode when useSuspenseQuery is called without a queryFn or initialData.
This helps developers avoid potential issues by ensuring at least one of them is provided.
@haesoo-y
Copy link
Copy Markdown
Contributor Author

Sorry, I misunderstood the root cause. I’ll submit the PR again.

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