MCPcopy Create free account
hub / github.com/TanStack/devtools / createReactPanel

Function createReactPanel

packages/devtools-utils/src/react/panel.tsx:23–56  ·  view source on GitHub ↗
(CoreClass: new () => TCoreDevtoolsClass)

Source from the content-addressed store, hash-verified

21 * ```
22 */
23export function createReactPanel<
24 TComponentProps extends TanStackDevtoolsPluginProps,
25 TCoreDevtoolsClass extends {
26 mount: (el: HTMLElement, props: TanStackDevtoolsPluginProps) => void
27 unmount: () => void
28 },
29>(CoreClass: new () => TCoreDevtoolsClass) {
30 function Panel(props: TComponentProps) {
31 const devToolRef = useRef<HTMLDivElement>(null)
32 const devtools = useRef<TCoreDevtoolsClass | null>(null)
33 useEffect(() => {
34 if (devtools.current) return
35 devtools.current = new CoreClass()
36
37 if (devToolRef.current) {
38 devtools.current.mount(devToolRef.current, props)
39 }
40
41 return () => {
42 if (devToolRef.current) {
43 devtools.current?.unmount()
44 devtools.current = null
45 }
46 }
47 }, [props])
48
49 return <div style={{ height: '100%' }} ref={devToolRef} />
50 }
51
52 function NoOpPanel(_props: TComponentProps) {
53 return <></>
54 }
55 return [Panel, NoOpPanel] as const
56}

Callers 2

A11yDevtools.tsFile · 0.90
A11yDevtools.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected