Open History to see the last commit
1import { createEffect, createMemo, onCleanup, onMount } from 'solid-js'
2import { onlineManager, useQueryClient } from '@tanstack/solid-query'
3import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
4import type { DevtoolsErrorType } from '@tanstack/query-devtools'
5import type { QueryClient } from '@tanstack/solid-query'
6import type { JSX } from 'solid-js'
7β
8export interface DevtoolsPanelOptions {
9 /**
10 * Custom instance of QueryClient
11 */
12 client?: QueryClient
13 /**
14 * Use this so you can define custom errors that can be shown in the devtools.
15 */
16 errorTypes?: Array<DevtoolsErrorType>
17 /**
18 * 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.
19 */
20 styleNonce?: string
21 /**
22 * Use this so you can attach the devtool's styles to specific element in the DOM.
23 */
24 shadowDOMTarget?: ShadowRoot
25β
26 /**
27 * Custom styles for the devtools panel
28 * @default { height: '500px' }
29 * @example { height: '100%' }
30 * @example { height: '100%', width: '100%' }
31 */
32 style?: JSX.CSSProperties
33β
34 /**
35 * Callback function that is called when the devtools panel is closed
36 */
37 onClose?: () => unknown
38 /**
39 * Set this to true to hide disabled queries from the devtools panel.
40 */
41 hideDisabledQueries?: boolean
42}
43β
44export default function SolidQueryDevtoolsPanel(props: DevtoolsPanelOptions) {
45 const queryClient = useQueryClient()
46 const client = createMemo(() => props.client || queryClient)
47 let ref!: HTMLDivElement
48 const { errorTypes, styleNonce, shadowDOMTarget, hideDisabledQueries } = props
49 const devtools = new TanstackQueryDevtoolsPanel({
50 client: client(),
51 queryFlavor: 'Solid Query',
52 version: '5',
53 onlineManager,
54 buttonPosition: 'bottom-left',
55 position: 'bottom',
56 initialIsOpen: true,
57 errorTypes,
58 styleNonce,
59 shadowDOMTarget,
60 onClose: props.onClose,
61 hideDisabledQueries,
62 })
63 createEffect(() => {
64 devtools.setClient(client())
65 })
66 createEffect(() => {
67 devtools.setOnClose(props.onClose ?? (() => {}))
68 })
69β
70 createEffect(() => {
71 devtools.setErrorTypes(props.errorTypes || [])
72 })
73β
74 onMount(() => {
75 devtools.mount(ref)
76 onCleanup(() => devtools.unmount())
77 })
78β
79 return (
80 <div
81 style={{ height: '500px', ...props.style }}
82 class="tsqd-parent-container"
83 ref={ref}
84 />
85 )
86}