useQuery without QueryProvider
I am using react query with nextJs 13 and sometime i want to useQuery without any cache just to use the loading, data, isError functions, is that possible?
6 Replies
quickest-silver•3y ago
Do you mean inside a react component?
conscious-sapphireOP•3y ago
Yes
quickest-silver•3y ago
well you definitely want some caching, right? You wouldn't want to fetch on every re-render of your component 🙂
conscious-sapphireOP•3y ago
Yes of course, but for example creating a queryClient just over that component and give it to the useQuery or smth similar. I was just wondering if there is a way around wrapping it in provider
quickest-silver•3y ago
in v5, you can pass a
queryClient directly to useQuery(options, client)
but you can't do new QueryClient() in there because then it would fetch on every render, so you still need to pass a stable value
the provider just takes the value, puts it in react context, and make it available. There's really no advantage to not doing thatconscious-sapphireOP•3y ago
that's exactly how i imagined it, thanks