Blog>
Snippets

Initialization and Providing QueryClient to the React Application

Shows how to create a QueryClient instance and provide it to a React application using the QueryClientProvider component.
import { QueryClient, QueryClientProvider } from 'react-query';
Import the necessary modules from react-query.
const queryClient = new QueryClient();
Create an instance of QueryClient. This will be used to configure options and provide the caching and fetching logic your application needs.
function App() {
  return (
    <QueryClientProvider client={queryClient}>
      {/* Your application components go here */}
    </QueryClientProvider>
  );
}
Wrap your application with the QueryClientProvider component and pass the queryClient instance as a prop. This makes the QueryClient instance available throughout your application.