Blog>
Snippets

Setting Up React Query in a React Application

Demonstrate how to install and set up React Query in a React application, including configuring the React Query cache provider.
npm install react-query
First, install React Query in your React project by running this command in your terminal.
import { QueryClient, QueryClientProvider } from 'react-query';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

// Create a client
const queryClient = new QueryClient();

ReactDOM.render(
  <React.StrictMode>
    <QueryClientProvider client={queryClient}>
      <App />
    </QueryClientProvider>
  </React.StrictMode>,
  document.getElementById('root')
);
Second, configure the React Query client and wrap your application's root component with the `QueryClientProvider` to make React Query available throughout the entire component tree.