Blog>
Snippets

Setting Up TanStack Config with React

Demonstrate how to integrate TanStack Config in a React application by setting up QueryClient and wrapping the application's root component with QueryClientProvider for global configuration.
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
Import the necessary modules from the React Query library.
const queryClient = new QueryClient();
Instantiate a new QueryClient. This object will be used to configure and manage the cache, requests, and other settings globally.
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
Import React and the application's root component.
ReactDOM.render(
  <QueryClientProvider client={queryClient}>
    <App />
  </QueryClientProvider>,
  document.getElementById('root')
);
Wrap the root component with QueryClientProvider and provide the queryClient instance. This sets up the React Query context, making it available throughout the application.