(CoreClass: new () => TCoreDevtoolsClass)
| 23 | * ``` |
| 24 | */ |
| 25 | export function createPreactPanel< |
| 26 | TComponentProps extends DevtoolsPanelProps, |
| 27 | TCoreDevtoolsClass extends { |
| 28 | mount: (el: HTMLElement, props: TanStackDevtoolsPluginProps) => void |
| 29 | unmount: () => void |
| 30 | }, |
| 31 | >(CoreClass: new () => TCoreDevtoolsClass) { |
| 32 | function Panel(props: TComponentProps) { |
| 33 | const devToolRef = useRef<HTMLDivElement>(null) |
| 34 | const devtools = useRef<TCoreDevtoolsClass | null>(null) |
| 35 | useEffect(() => { |
| 36 | if (devtools.current) return |
| 37 | devtools.current = new CoreClass() |
| 38 | // Preact 11 clears the ref before this effect's cleanup runs. |
| 39 | const el = devToolRef.current |
| 40 | |
| 41 | if (el) { |
| 42 | devtools.current.mount(el, props) |
| 43 | } |
| 44 | |
| 45 | return () => { |
| 46 | if (el) { |
| 47 | devtools.current?.unmount() |
| 48 | devtools.current = null |
| 49 | } |
| 50 | } |
| 51 | }, [props]) |
| 52 | |
| 53 | return <div style={{ height: '100%' }} ref={devToolRef} /> |
| 54 | } |
| 55 | |
| 56 | function NoOpPanel(_props: TComponentProps) { |
| 57 | return <></> |
| 58 | } |
| 59 | return [Panel, NoOpPanel] as const |
| 60 | } |
nothing calls this directly
no outgoing calls
no test coverage detected