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