Skip to content

Commit e40fcce

Browse files
committed
feat: enable TanStack Query DevTools browser extension
- Expose QueryClient on window for integration with TanStack Query DevTools (browser extension) - Documented alternative: TanStack Query Devtools floating/embedded component (see https://tanstack.com/query/latest/docs/framework/react/devtools) - Chose browser extension to keep project dependencies clean and offload devtools responsibility to the developer
1 parent 9bccaaa commit e40fcce

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/react-query-setup.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,21 @@ function App() {
3232
```
3333

3434
If you do not pass the same QueryClient instance, each provider will maintain its own cache, which can lead to unexpected behavior.
35+
36+
## TanStack Query DevTools Integration
37+
38+
stac-react automatically connects your QueryClient to the [TanStack Query DevTools browser extension](https://tanstack.com/query/latest/docs/framework/react/devtools) when running in development mode. This allows you to inspect queries, mutations, and cache directly in your browser without adding extra dependencies to your project.
39+
40+
**How it works:**
41+
42+
- In development (`process.env.NODE_ENV === 'development'`), stac-react exposes the QueryClient on `window.__TANSTACK_QUERY_CLIENT__`.
43+
- The browser extension detects this and connects automatically.
44+
- No code changes or additional dependencies are required.
45+
46+
> By default, React Query Devtools are only included in bundles when process.env.NODE_ENV === 'development', so you don't need to worry about excluding them during a production build.
47+
48+
**Alternative:**
49+
50+
- If you prefer an embedded/floating devtools panel, you can install and use the [TanStack Query Devtools React component](https://tanstack.com/query/latest/docs/framework/react/devtools#floating-devtools) in your app. This adds a UI panel directly to your app, but increases bundle size and dependencies.
51+
52+
For more details, see the [TanStack Query DevTools documentation](https://tanstack.com/query/latest/docs/framework/react/devtools).

src/context/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ export function StacApiProvider({ children, apiUrl, options, queryClient }: Stac
5151
const defaultClient = useMemo(() => new QueryClient(), []);
5252
const client: QueryClient = queryClient ?? defaultClient;
5353

54+
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
55+
// Connect TanStack Query DevTools (browser extension)
56+
window.__TANSTACK_QUERY_CLIENT__ = client;
57+
}
58+
5459
return (
5560
<QueryClientProvider client={client}>
5661
<StacApiContext.Provider value={contextValue}>{children}</StacApiContext.Provider>
5762
</QueryClientProvider>
5863
);
5964
}
65+
66+
declare global {
67+
interface Window {
68+
__TANSTACK_QUERY_CLIENT__: import('@tanstack/query-core').QueryClient;
69+
}
70+
}

0 commit comments

Comments
 (0)