Hi all 👋
I use SWR at wrok, and wanted something like TanStack Query's in-app devtools panel. There are a few SWR tools around already, including the SWRDevTools extension and swr-cache-devtools, but I wanted to go further on a few things, so I built swr-devtools-react:
- it removes itself from production builds, so there's no
NODE_ENVcheck to add - it shows SWR's full status for each key (loading, validating, success, error, idle), and labels
useSWRInfiniteanduseSWRSubscriptionkeys - the panel can be embedded in other devtools, starting with a TanStack Devtools plugin
Add one component inside your <SWRConfig>:
import { SWRConfig } from 'swr';import { SWRDevtools } from 'swr-devtools-react';<SWRConfig value={{ fetcher /* your existing SWR config */ }}> <App /> <SWRDevtools /></SWRConfig>A button appears in the corner of the page. It opens a panel that shows:
- every key in the cache with its status (loading, validating, success, error, idle), updating live
useSWRInfiniteanduseSWRSubscriptionkeys, labelled- the data for any key as a collapsible JSON tree, with search and sort
From the panel you can revalidate, edit or delete a key, or clear the whole cache. Editing a key's data updates your app straight away, which I've found handy for checking empty and error states without touching the API.
It works alongside the SWRDevTools browser extension and doesn't need anything installed in the browser.
Next on the list:
- a TanStack Devtools plugin, so SWR can sit next to TanStack Query and Router in one panel
- a mutations tab for
useSWRMutation - choosing between multiple SWR caches
- a dark mode toggle
Repo: https://github.com/TheFlyer1983/swr-devtools-react npm: https://www.npmjs.com/package/swr-devtools-react npmx.dev: https://npmx.dev/package/swr-devtools-react
It's early days, so feedback from people using SWR day to day would really help. What would you want a devtools panel to show that this doesn't yet? Bugs and feature requests are welcome as issues, and longer ideas in Discussions.