-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
[openapi-react-query] Uncaught Error: No QueryClient set, use QueryClientProvider to set one #1947
Comments
Update: I figured it out. I'm going to make a PR to improve the docs. |
Hello @bogoblin How did you manage to resolve this error? |
In the root of your app, you need to create a queryClient with react-query. My root looks like this: import {StrictMode} from 'react'
import {createRoot} from 'react-dom/client'
import './index.css'
import {FoobarLibrary} from "./foobarLibrary.tsx";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import {PlaybackControls} from "./playbackControls.tsx";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false
}
}
});
createRoot(document.getElementById('root')!).render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<FoobarLibrary playlistId="p2"/>
<PlaybackControls />
</QueryClientProvider>
</StrictMode>,
) |
Thank you so much for the solution! This is incredibly helpful. |
This is a requirement as per the |
Just to clarify for the documentation - does this only occour when the client is defined in another file than where we use the query? |
No this will always happen if you dont explicitly provide a QueryClient or implicitly using a QueryClientProvider. https://tanstack.com/query/latest/docs/framework/react/quick-start |
I have a QueryClientProvider and can use standard tanstack-query |
The docs covers setting up 'openapi-react-query,' so this information should be included as part of the complete setup guide. Without it, users may encounter difficulties, as seen in this instance (me included) |
Description
I'm trying out openapi-react-query and I don't seem to be able to get it to work. I'm creating a client like so:
...and then using it in a component like so:
However, when I run this in the browser, I get the following error message:
I've been reading online about react-query and it seems you need to add a QueryClientProvider around your app, but I'm not sure how to do that.
Proposal
If someone can help me fix this I will contribute to the docs and add a more helpful error message so that others don't have this issue.
Checklist
The text was updated successfully, but these errors were encountered: