Skip to content

Handle undefined queryClient when passed as thunk #2

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

Open
wants to merge 1 commit into
base: svelte-5-adapter-derived-by
Choose a base branch
from

Conversation

hmnd
Copy link

@hmnd hmnd commented Apr 15, 2025

Currently, the queryClient param is optional, but this doesn't account for a query-creating function like this, where the queryClient is optional. This PR allows undefined to be returned, since undefined is already expected and supported in useQueryClient.

function createMyQuery(ctx: () => { queryClient?: QueryClient }) {
  return createQuery(() => ({
    queryKey: ['mykey'],
    queryFn: () => ({ myreturn: 'cool' }),
  }), () => ctx?.().queryClient); // queryClient returned here may be undefined 
}

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