Skip to content

Conversation

haesoo-y
Copy link
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
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