Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

CustomDevtoolsPanel.tsx

23 lines589 Bytes

1import { useEffect, useState } from 'react'
2import { DevtoolsEventClient } from './eventClient.ts'
3​
4export default function CustomDevtoolPanel() {
5 const [state, setState] = useState<
6 { count: number; history: Array<number> } | undefined
7 >()
8​
9 useEffect(() => {
10 // subscribe to the emitted event
11 const cleanup = DevtoolsEventClient.on('counter-state', (e) =>
12 setState(e.payload),
13 )
14 return cleanup
15 }, [])
16​
17 return (
18 <div>
19 <div>counter state: {state?.count}</div>
20 <div>counter history: {JSON.stringify(state?.history)}</div>
21 </div>
22 )