Blog>
Snippets

Setting Up React Query in a React Project

Show how to install React Query, set up QueryClient, and wrap your application with QueryClientProvider for global usage.
npm install react-query axios
This command installs React Query and Axios in your project. Axios is used for making HTTP requests.
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();

// Provide the client to your App
ReactDOM.render(
  <QueryClientProvider client={queryClient}>
    <App />
  </QueryClientProvider>,
  document.getElementById('root')
);
Here we're importing necessary components from React Query and wrapping our <App/> component with <QueryClientProvider/>. This makes React Query available throughout the app.