-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
52 lines (48 loc) · 1.19 KB
/
index.tsx
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
42
43
44
45
46
47
48
49
50
51
52
import { trpcClient } from "@/trpc";
import { webcrypto } from "crypto";
import Head from "next/head";
import { useState } from "react";
export default function Home() {
const [enabled, setEnabled] = useState(false);
const [messages, setMessages] = useState<Array<{ id: string; idk: number }>>(
[]
);
trpcClient.numbers.useSubscription(
{
count: 30,
},
{
enabled,
onData(data) {
setMessages((prev) => [...prev, data]);
},
}
);
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<button onClick={() => setEnabled((p) => !p)}>
{enabled ? "Stop" : "Start"}
</button>
<div
style={{
backgroundColor: "lightgray",
maxWidth: "50%",
padding: ".5em",
margin: ".5em",
}}
>
{messages.map((m) => (
<div key={m.id}>{m.idk}</div>
))}
</div>
</main>
</>
);
}