Introduction to TanStack Devtools
Welcome to Chapter 15! Throughout this guide, we’ve been building robust applications using various parts of the TanStack ecosystem, from managing server state with Query to handling complex navigation with Router. As our applications grow, understanding their internal workings becomes crucial. This is where TanStack Devtools shine!
In this chapter, we’ll dive deep into the TanStack Devtools, specifically focusing on those for TanStack Query and TanStack Router. These powerful browser extensions and components provide an invaluable window into your application’s state, helping you understand, debug, and optimize your code. You’ll learn how to integrate them into your project and leverage their features to gain real-time insights into data fetching, caching, routing, and more.
Before we begin, it’s assumed you have a working knowledge of TanStack Query and TanStack Router, as covered in previous chapters. We’ll be adding the Devtools to an existing application setup, so having a project with some queries and routes already defined will be beneficial.
Core Concepts: Why Devtools are Your Best Friends
Developing modern web applications often involves managing complex asynchronous operations and intricate routing logic. Without proper tools, debugging these aspects can feel like navigating a maze blindfolded. TanStack Devtools are designed to bring clarity to this complexity.
What are Developer Tools?
Developer tools, or “devtools,” in the context of TanStack, are UI components or browser extensions that provide a visual representation and interactive interface for the internal state and operations of a library. They allow you to:
- Inspect State: See the current state of your queries, mutations, routes, and their associated data.
- Monitor Activity: Observe data fetching, caching, and routing events as they happen in real-time.
- Debug Issues: Quickly identify why a query isn’t fetching, why data is stale, or why a route isn’t resolving as expected.
- Optimize Performance: Understand cache behavior, identify unnecessary re-fetches, and analyze route transitions.
- Manipulate State (for debugging): Some devtools allow you to manually invalidate caches or trigger actions to test scenarios.
Why are Devtools Crucial for TanStack?
TanStack libraries, especially Query and Router, manage significant amounts of asynchronous and derived state.
- TanStack Query deals with server-state, caching, background re-fetching, data synchronization, and mutations. Without Devtools, understanding why a query is in a
stalestate, when it was last fetched, or what data is currently in its cache would be incredibly difficult. - TanStack Router manages complex URL-driven state, route loaders, search parameters, and nested routing. Devtools help visualize the route tree, inspect resolved loader data, and trace navigation history, which is vital for debugging routing issues.
In essence, Devtools demystify the “magic” happening behind the scenes, giving you the transparency needed to build confident, performant applications.
Step-by-Step Implementation: Integrating TanStack Devtools
Let’s integrate the Devtools for TanStack Query and TanStack Router into a React application. We’ll assume you have a basic React project set up with react-query (v5) and tanstack-router (v1) already in use.
1. Setting Up TanStack Query Devtools
The TanStack Query Devtools provide a dedicated interface to inspect all aspects of your queries and mutations.
Installation
First, open your terminal and install the Devtools package. We’ll use the @latest tag to ensure we get the most current stable version, which aligns with TanStack Query v5.
npm install @tanstack/react-query-devtools@latest
# or yarn add @tanstack/react-query-devtools@latest
# or pnpm add @tanstack/react-query-devtools@latest
This installs @tanstack/react-query-devtools version 5.x.x (as of 2026-01-07).
Integration into Your React App
Now, let’s add the Devtools component to your React application. Typically, you’ll place it near your QueryClientProvider.
Open your main application file (e.g., src/App.tsx or src/main.tsx) and modify it as follows:
// src/App.tsx (or wherever your QueryClientProvider is)
import React from 'react';
import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; // <-- Import me!
import AppContent from './AppContent'; // Your main application component
const queryClient = new QueryClient();
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<AppContent />
{/*
Add the Devtools component here.
It's recommended to include it only in development environments.
*/}
{process.env.NODE_ENV === 'development' && (
<ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
)}
</QueryClientProvider>
</React.StrictMode>,
);
What did we add?
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';: This line imports the Devtools component.<ReactQueryDevtools initialIsOpen={false} position="bottom-right" />: This is the component itself.initialIsOpen={false}: This prop determines if the Devtools panel should be open by default when the application loads. Setting it tofalsemeans it will be minimized, usually as a small icon.position="bottom-right": This controls where the Devtools toggle button appears on your screen. Other options include"top-left","top-right","bottom-left".
{process.env.NODE_ENV === 'development' && (...) }: This is a crucial best practice. You only want the Devtools to be active in your development environment. In production, they add unnecessary bundle size and could expose internal state. This conditional rendering ensures they are stripped out during a production build.
Now, run your application (npm run dev). You should see a small TanStack Query logo or button in the corner of your screen (bottom-right in our example). Click it to open the Devtools panel!
Exploring Query Devtools Features
Once open, the Query Devtools offer several tabs:
- Queries: This is the most frequently used tab. It lists all active queries, their keys, statuses (e.g.,
fetching,success,error,paused), and the data they hold.- Click on any query to see detailed information: query key, data, last updated timestamp,
staleTime,gcTime, and more. - You can manually refetch, invalidate, or reset individual queries from here.
- Click on any query to see detailed information: query key, data, last updated timestamp,
- Mutations: This tab displays information about any mutations (
useMutation) that have occurred, including their variables, status, and results. - Logs: Provides a chronological log of Query-related events.
Mini-Challenge: Inspecting a Query
- If you don’t have one, create a simple
useQueryhook in yourAppContentcomponent that fetches some data (e.g., from a fake API or a local array). - Open your browser’s developer tools and then open the TanStack Query Devtools.
- Challenge: Find your
useQueryhook’s entry in the “Queries” tab. Observe its status as it fetches data. Click on it and examine thedataproperty. - Hint: Try refreshing your page and watch the query transition from
fetchingtosuccess. - What to observe/learn: Notice how the Devtools provide immediate visual feedback on the state of your data fetching, making it easy to confirm if your queries are running as expected and what data they contain.
2. Setting Up TanStack Router Devtools
Just like Query, TanStack Router also offers dedicated Devtools to visualize your routing tree, active routes, and loader data.
Installation
Install the Router Devtools package:
npm install @tanstack/router-devtools@latest
# or yarn add @tanstack/router-devtools@latest
# or pnpm add @tanstack/router-devtools@latest
This installs @tanstack/router-devtools version 1.x.x (as of 2026-01-07).
Integration into Your React App
The Router Devtools should be placed inside your RouterProvider or close to it.
Modify your main application file (e.g., src/main.tsx or src/App.tsx) where your router is provided:
// src/main.tsx (or wherever your RouterProvider is)
import React from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/router-devtools'; // <-- Import me!
import { router } from './router'; // Your router instance
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<RouterProvider router={router}>
{/*
Add the Router Devtools here.
Again, only in development environments.
*/}
{process.env.NODE_ENV === 'development' && (
<TanStackRouterDevtools initialIsOpen={false} position="bottom-left" />
)}
</RouterProvider>
</React.StrictMode>,
);
What did we add?
import { TanStackRouterDevtools } from '@tanstack/router-devtools';: This imports the Router Devtools component.<TanStackRouterDevtools initialIsOpen={false} position="bottom-left" />: This is the component.initialIsOpen={false}: Similar to Query Devtools, controls initial visibility.position="bottom-left": Sets the position of the toggle button. Make sure it doesn’t conflict with other Devtools if you’re using multiple.
{process.env.NODE_ENV === 'development' && (...) }: The same conditional rendering for development environments only.
Run your application (npm run dev). You should now see another toggle button (a TanStack Router logo) on your screen. Click it to open the Router Devtools panel.
Exploring Router Devtools Features
The Router Devtools offer powerful insights into your application’s navigation:
- Routes: This tab displays your entire route tree, showing parent-child relationships.
- Active routes are highlighted, making it easy to see which routes are currently matched.
- Click on an active route to inspect its
params,searchparameters, and especially itsloaderData. This is incredibly useful for debugging data passed from loaders.
- History: Shows a chronological list of all navigation events, including the
fromandtopaths. This helps trace user journeys and debug unexpected redirects or navigation issues. - Loaders: Provides a direct view into the state of your route loaders, indicating if they are pending, resolved, or errored.
Mini-Challenge: Debugging Route Data
Ensure you have a route in your
router.ts(or similar file) that uses aloaderto fetch some data. For example:// src/router.ts (partial example) import { createRouter, Route } from '@tanstack/react-router'; const rootRoute = new Route({ path: '/', component: () => <div>Home</div> }); const postsRoute = new Route({ getParentRoute: () => rootRoute, path: 'posts', loader: async () => { // Simulate fetching posts const posts = await new Promise(resolve => setTimeout(() => resolve([ { id: 1, title: 'First Post' }, { id: 2, title: 'Second Post' }, ]), 500)); return { posts }; }, component: () => { const { posts } = postsRoute.useLoaderData(); return ( <div> <h2>Posts</h2> <ul> {posts.map(post => ( <li key={post.id}>{post.title}</li> ))} </ul> </div> ); }, }); const routeTree = rootRoute.addChildren([postsRoute]); export const router = createRouter({ routeTree });Navigate to
/postsin your application.Challenge: Open the TanStack Router Devtools. Go to the “Routes” tab, find the
/postsroute, and inspect itsloaderData.Hint: Observe the
loaderDataobject and confirm it contains thepostsarray you defined in the loader.What to observe/learn: The Devtools allow you to confirm that your route loaders are correctly fetching and providing the expected data to your components, without needing to add
console.logstatements everywhere.
Common Pitfalls & Troubleshooting
Even with Devtools, you might encounter situations where things don’t work as expected. Here are some common pitfalls and how to troubleshoot them:
Devtools Not Showing Up:
- Check Installation: Double-check that
@tanstack/react-query-devtoolsand@tanstack/router-devtoolsare correctly installed inpackage.json. - Check Integration: Ensure the
ReactQueryDevtoolsandTanStackRouterDevtoolscomponents are placed correctly within their respective providers (QueryClientProviderandRouterProvider). - Development Environment: Verify that
process.env.NODE_ENVis indeed'development'. If you’re running a production build locally, the Devtools might be conditionally excluded. - Conflicting Positions: If you have multiple Devtools, ensure their
positionprops don’t overlap, making one inaccessible.
- Check Installation: Double-check that
Misinterpreting TanStack Query States:
- Stale vs. Fresh: Remember that TanStack Query marks data as
staleafter a certainstaleTime(default: 0). A stale query will re-fetch in the background when observed. Don’t confusestalewitherrororfetching. - Garbage Collection (
gcTime): If a query disappears from the Devtools, it might have been garbage collected. By default, queries are garbage collected after 5 minutes (gcTime) if they are no longer observed by any component. If you need to inspect inactive queries for longer, increasegcTimein yourQueryClientconfiguration. - Refetching Behavior: If a query keeps refetching unexpectedly, check its
refetchOnWindowFocus,refetchOnMount, andrefetchIntervaloptions. The Devtools “Logs” tab can help identify what triggered a refetch.
- Stale vs. Fresh: Remember that TanStack Query marks data as
Router State Not Updating / Incorrect Loader Data:
- Route Matching: Ensure your URL path correctly matches the route definition in your
router.ts. The “Routes” tab in Router Devtools will show you the active routes. - Loader Dependencies: If a loader isn’t re-running when expected, check if its dependencies (e.g.,
params,search) have actually changed. Also, ensure you’re usinguseLoaderData()within the correct route component. - Search Params: TanStack Router handles
searchparameters with type safety. If your search params aren’t showing up or are incorrect, verify yourparseSearchandvalidateSearchfunctions for the route. The Router Devtools will show the parsed search object.
- Route Matching: Ensure your URL path correctly matches the route definition in your
Summary
In this chapter, we’ve explored the incredible value that TanStack Devtools bring to your development workflow.
Here are the key takeaways:
- Indispensable for DX: TanStack Devtools for Query and Router significantly improve the developer experience by providing visual, real-time insights into your application’s server state and routing logic.
- Easy Integration: Both
@tanstack/react-query-devtools(v5) and@tanstack/router-devtools(v1) are straightforward to install and integrate into your React application, typically placed near their respective providers. - Development Only: Always remember to conditionally render Devtools only in your
developmentenvironment to avoid unnecessary bundle size and potential security risks in production. - Query Devtools Insights: Use the Query Devtools to inspect query keys, statuses (fetching, success, error), cached data, mutation states, and manually trigger refetches or invalidations.
- Router Devtools Insights: Leverage Router Devtools to visualize your route tree, inspect active routes, verify
paramsandsearchparameters, and examine theloaderDataresolved by your route loaders. - Troubleshooting Power: The Devtools are your first line of defense against common issues like unexpected data fetching, stale data, incorrect routing, or missing loader data.
By making TanStack Devtools an integral part of your development process, you’ll gain a deeper understanding of your application’s behavior, leading to faster debugging, better performance, and a more enjoyable development experience.
What’s Next?
With a solid grasp of debugging, you’re now well-equipped to tackle more advanced topics. In the next chapter, we’ll shift our focus to architectural decision-making and best practices for structuring large-scale applications using the TanStack ecosystem.
References
- TanStack Query Docs - Devtools
- TanStack Router Docs - Devtools
- TanStack Query GitHub Repository
- TanStack Router GitHub Repository
This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.