In the quick start docs of react-query here there is the following example:
// Create a client
const queryClient = new QueryClient();
const App = function () {
return (
// Provide the client to your App
<QueryClientProvider client={ queryClient }>
<Todos />
</QueryClientProvider>
);
};
const Todos = function () {
// Access the client
const queryClient = useQueryClient();
// ...
return (
<>
...
</>
);
};
but I cannot understand why I should use the useQueryClient hook inside the Todos.
// Access the client
const queryClient = useQueryClient();
I mean couldn't I just export the the queryClient
instance from my main file:
// App.js
export const queryClient = new QueryClient();
and then import it immediately inside Todos ?
// Todos.js
import { queryClient } from './App';
The reason I am asking this is because I want to use the queryClient instance apart from react (maybe inside a listener function from another library) and I was wondering that if I can only access it from a react hook (in order to not mess something up) then I won't be able to use it in some other way.