-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathclient-plugin.tsx
More file actions
41 lines (39 loc) · 1.15 KB
/
client-plugin.tsx
File metadata and controls
41 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { queryPlugin } from '@/plugin'
import { useEffect, useState } from 'react'
export default function ClientPlugin() {
const [events, setEvents] = useState<
Array<{ type: string; payload: { title: string; description: string } }>
>([])
useEffect(() => {
const cleanup = queryPlugin.on('test', (event) => {
console.log('Received message in here:', event)
setEvents((prev) => [...prev, event as any])
})
return cleanup
}, [])
return (
<div>
<h1>Client Plugin Initialized</h1>
<p>Devtools Client is connected.</p>
<button
className="bg-blue-500 text-white px-4 py-2 rounded"
onClick={() => {
console.log('Button clicked, emitting event')
queryPlugin.emit('test', {
title: 'Button Clicked',
description:
'This is a custom event triggered by the client plugin.',
})
}}
>
Click me
</button>
{events.map((event, i) => (
<div key={i}>
<h2>{event.payload.title}</h2>
<p style={{ color: 'gray' }}>{event.payload.description}</p>
</div>
))}
</div>
)
}