Blog>
Snippets

Integrating React Query DevTools in a React Project

Showcase the code required to integrate React Query DevTools into a React application, highlighting the installation steps and the addition to the React component tree.
import { ReactQueryDevtools } from 'react-query/devtools';
First, import ReactQueryDevtools from 'react-query/devtools'. This component is used to enable the development tools for React Query.
const queryClient = new QueryClient();
Create a new instance of QueryClient. This object is used to manage queries and cache within the React Query ecosystem.
<QueryClientProvider client={queryClient}>
  <App />
  {process.env.NODE_ENV === 'development' && <ReactQueryDevtools initialIsOpen={false} />}
</QueryClientProvider>
Within the JSX of your application root, wrap your <App/> component with <QueryClientProvider/> and pass the queryClient instance as a prop. Then conditionally add <ReactQueryDevtools/> based on the environment, ensuring the Dev Tools are only included in development builds. The 'initialIsOpen' prop is used to control the initial visibility of the Dev Tools.