Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

devtools.md

75 lines2.5 KB

1---
2id: devtools
3title: Devtools
4---
5​
6## Install and Import the Devtools
7​
8The devtools are a separate package that you need to install:
9​
10```bash
11npm i @tanstack/svelte-query-devtools
12```
13​
14or
15​
16```bash
17pnpm add @tanstack/svelte-query-devtools
18```
19​
20or
21​
22```bash
23yarn add @tanstack/svelte-query-devtools
24```
25​
26or
27​
28```bash
29bun add @tanstack/svelte-query-devtools
30```
31​
32You can import the devtools like this:
33​
34```ts
35import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
36```
37​
38## Floating Mode
39​
40Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
41​
42Place the following code as high in your Svelte app as you can. The closer it is to the root of the page, the better it will work!
43​
44```ts
45<script>
46 import { QueryClientProvider } from '@tanstack/svelte-query'
47 import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
48</script>
49​
50<QueryClientProvider client={queryClient}>
51 {/* The rest of your application */}
52 <SvelteQueryDevtools />
53</QueryClientProvider>
54```
55​
56### Options
57​
58- `initialIsOpen: Boolean`
59 - Set this `true` if you want the dev tools to default to being open
60- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
61 - Defaults to `bottom-right`
62 - The position of the TanStack logo to open and close the devtools panel
63 - If `relative`, the button is placed in the location that you render the devtools.
64- `position?: "top" | "bottom" | "left" | "right"`
65 - Defaults to `bottom`
66 - The position of the Svelte Query devtools panel
67- `client?: QueryClient`,
68 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
69- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
70 - Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
71- `styleNonce?: string`
72 - Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
73- `shadowDOMTarget?: ShadowRoot`
74 - Default behavior will apply the devtool's styles to the head tag within the DOM.
75 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.