React Query Dev Tools for React Native
The `react-native-react-query-devtools` package provides a dedicated debugging interface for applications utilizing TanStack React Query within a React Native environment. It offers functionalities analogous to its web counterpart, including an online/offline network toggle, comprehensive cache management for clearing queries and mutations, and a movable, resizable modal interface. The package aims to enhance the debugging experience on mobile platforms with a modern UI, improved query and mutation inspectors, and a copy-to-clipboard feature (which requires a platform-specific `onCopy` implementation). While the current npm metadata indicates version 1.5.1, recent changelogs from `@buoy-gg` (potentially a related project or monorepo by the same author) show versions up to 2.1.10, suggesting ongoing, active development, though the direct versioning for this specific package is ambiguous. Its key differentiator is adapting the well-known React Query Dev Tools experience specifically for React Native, addressing mobile-specific interaction patterns and environmental requirements.
Common errors
-
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `RootLayoutNav`.
cause This error often occurs if `react-native-svg` is not installed or properly linked, as `DevToolsBubble` relies on it for its internal components.fixEnsure `react-native-svg` is installed (`npm install react-native-svg`) and, for bare React Native projects, native modules are linked (`npx react-native autolink-android-app` and `cd ios && pod install`). -
TypeError: Cannot read property 'setStringAsync' of undefined
cause The `onCopy` function attempts to use `Clipboard.setStringAsync` (for Expo) but `expo-clipboard` is not installed or imported correctly.fixFor Expo, install `expo-clipboard` (`npx expo install expo-clipboard`) and import it as `import * as Clipboard from 'expo-clipboard';`. For React Native CLI, ensure `import { Clipboard } from 'react-native';` and use `Clipboard.setString(text)`. -
Invariant Violation: `DevToolsBubble` uses `QueryClient` context but no `QueryClientProvider` was found. Did you forget to add `QueryClientProvider` to your app?
cause `DevToolsBubble` is rendered without being wrapped by a `QueryClientProvider` from `@tanstack/react-query`, which is necessary to provide the `QueryClient` instance.fixEnsure `DevToolsBubble` is a child of `QueryClientProvider` and that `QueryClientProvider` is initialized with a `new QueryClient()` instance, as shown in the quickstart.
Warnings
- breaking The README explicitly states prerequisites of React version 19.1.0 or above and React Native 0.78.0 or above (for React 19 support). This can be more restrictive than the peer dependency range `^18 || ^19` for React, potentially breaking applications on older React versions.
- gotcha The `react-native-svg` package is a mandatory peer dependency. Failure to install and link it correctly will result in runtime errors related to UI rendering within the dev tools.
- gotcha The `onCopy` prop is required by `DevToolsBubble` and must provide a function that handles copying text to the clipboard using a platform-specific API (e.g., `expo-clipboard` for Expo or `react-native/Libraries/Components/Clipboard/Clipboard` for React Native CLI). Omitting or incorrectly implementing this prop will disable copy functionality and may cause errors.
Install
-
npm install react-native-react-query-devtools -
yarn add react-native-react-query-devtools -
pnpm add react-native-react-query-devtools
Imports
- DevToolsBubble
import DevToolsBubble from 'react-native-react-query-devtools';
import { DevToolsBubble } from 'react-native-react-query-devtools'; - QueryClientProvider
import { QueryClientProvider, QueryClient } from '@tanstack/react-query'; - Clipboard
import * as Clipboard from 'expo-clipboard'; // For Expo // OR import { Clipboard } from 'react-native'; // For React Native CLI
Quickstart
import { DevToolsBubble } from "react-native-react-query-devtools";
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import { useColorScheme } from 'react-native';
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native'; // Assuming @react-navigation/native for theming, adjust as needed
import { Stack } from 'expo-router'; // Assuming Expo Router, adjust as needed
import * as Clipboard from 'expo-clipboard'; // For Expo; use 'react-native' for bare React Native CLI
function RootLayoutNav() {
const colorScheme = useColorScheme();
const queryClient = new QueryClient();
// Define your copy function based on your platform (Expo or React Native CLI)
const onCopy = async (text: string) => {
try {
// For Expo:
await Clipboard.setStringAsync(text);
// OR for React Native CLI (uncomment and adjust if not using Expo):
// await Clipboard.setString(text);
return true;
} catch (e) {
console.error("Failed to copy to clipboard:", e);
return false;
}
};
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
{/* Your app's navigation stack or main components go here */}
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="modal" options={{ presentation: "modal" }} />
</Stack>
</ThemeProvider>
{/* DevToolsBubble should be placed outside the main app views to float on top */}
<DevToolsBubble onCopy={onCopy} queryClient={queryClient} />
</QueryClientProvider>
);
}
export default RootLayoutNav;