Jotai DevTools and Debugging
You'll learn how to inspect and debug your Jotai atoms using the official DevTools package.
Understanding Jotai's Debugging Challenge
When working with Jotai's atomic state, you have many small, distributed pieces of state scattered throughout your application. Unlike a single global store, it can be tricky to see what atom values currently hold, how they relate to each other, and what's causing updates. That's where jotai-devtools comes in—it gives you visibility into your atom graph during development.
Installing and Setting Up DevTools
First, install the package:
npm install jotai-devtools
Then wrap your app (or a section of it) with the DevTools component:
import { DevTools } from 'jotai-devtools';
import { useAtom } from 'jotai';
import { countAtom, doubleAtom } from './atoms';
function App() {
return (
<>
<DevTools />
<MyComponents />
</>
);
}
The DevTools component renders an inspector panel in your browser that shows all atoms in scope.
What You Can Inspect
The DevTools panel displays:
- Current atom values: See the live value of each atom
- Atom dependencies: Visualize which atoms depend on others (e.g., derived atoms)
- Atom labels: See atom names if you've added debug labels
- Update history: Track when atoms change
Think of it like opening the hood of your car—you can finally see the engine (your atoms) running in real-time instead of just watching the dashboard (your UI).
Key Takeaway: The jotai-devtools package provides a visual inspector for your atoms, showing their current values and dependency relationships during development—essential for debugging complex atomic state.