Open History to see the last commit
1import { createEffect, createMemo, onCleanup, onMount } from 'solid-js'
2import { onlineManager, useQueryClient } from '@tanstack/solid-query'
3import { TanstackQueryDevtools } from '@tanstack/query-devtools'
4import type {
5 DevtoolsButtonPosition,
6 DevtoolsErrorType,
7 DevtoolsPosition,
8 Theme,
9} from '@tanstack/query-devtools'
10import type { QueryClient } from '@tanstack/solid-query'
11β
12interface DevtoolsOptions {
13 /**
14 * Set this true if you want the dev tools to default to being open
15 */
16 initialIsOpen?: boolean
17 /**
18 * The position of the TanStack logo to open and close the devtools panel.
19 * 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'relative'
20 *
21 * @defaultValue bottom-right
22 */
23 buttonPosition?: DevtoolsButtonPosition
24 /**
25 * The position of the Solid Query devtools panel.
26 * 'top' | 'bottom' | 'left' | 'right'
27 *
28 * @defaultValue bottom
29 */
30 position?: DevtoolsPosition
31 /**
32 * Custom instance of QueryClient
33 */
34 client?: QueryClient
35 /**
36 * Use this so you can define custom errors that can be shown in the devtools.
37 */
38 errorTypes?: Array<DevtoolsErrorType>
39 /**
40 * 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.
41 */
42 styleNonce?: string
43 /**
44 * Use this so you can attach the devtool's styles to specific element in the DOM.
45 */
46 shadowDOMTarget?: ShadowRoot
47 /**
48 * Set this to true to hide disabled queries from the devtools panel.
49 */
50 hideDisabledQueries?: boolean
51 /**
52 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
53 *
54 * @defaultValue system
55 */
56 theme?: Theme
57}
58β
59export default function SolidQueryDevtools(props: DevtoolsOptions) {
60 const queryClient = useQueryClient(props.client)
61 const client = createMemo(() => queryClient)
62 let ref!: HTMLDivElement
63 const devtools = new TanstackQueryDevtools({
64 client: client(),
65 queryFlavor: 'Solid Query',
66 version: '5',
67 onlineManager,
68 buttonPosition: props.buttonPosition,
69 position: props.position,
70 initialIsOpen: props.initialIsOpen,
71 errorTypes: props.errorTypes,
72 styleNonce: props.styleNonce,
73 shadowDOMTarget: props.shadowDOMTarget,
74 hideDisabledQueries: props.hideDisabledQueries,
75 theme: props.theme,
76 })
77β
78 createEffect(() => {
79 devtools.setClient(client())
80 })
81β
82 createEffect(() => {
83 const buttonPos = props.buttonPosition
84 if (buttonPos) {
85 devtools.setButtonPosition(buttonPos)
86 }
87 })
88β
89 createEffect(() => {
90 const pos = props.position
91 if (pos) {
92 devtools.setPosition(pos)
93 }
94 })
95β
96 createEffect(() => {
97 devtools.setInitialIsOpen(props.initialIsOpen || false)
98 })
99β
100 createEffect(() => {
101 devtools.setErrorTypes(props.errorTypes || [])
102 })
103β
104 createEffect(() => {
105 devtools.setTheme(props.theme || 'system')
106 })
107β
108 onMount(() => {
109 devtools.mount(ref)
110 onCleanup(() => devtools.unmount())
111 })
112β
113 return <div class="tsqd-parent-container" ref={ref}></div>
114}