-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcontext.jsx
More file actions
38 lines (36 loc) · 1.09 KB
/
context.jsx
File metadata and controls
38 lines (36 loc) · 1.09 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
import React, { useState } from "react";
import { useLiveReact } from "live_react";
export function Context({ count }) {
const [amount, setAmount] = useState(1);
const { pushEvent, ...rest } = useLiveReact();
console.log(rest);
return (
<div className="flex flex-col justify-center items-center gap-4">
<div className="flex flex-row items-center justify-center gap-10">
<button
className="px-4 py-2 rounded bg-red-500 text-white"
onClick={() => pushEvent("set_count", { value: count - amount })}
>
-{amount}
</button>
<span className="text-xl">{count}</span>
<button
className="px-4 py-2 rounded bg-green-500 text-white"
onClick={() => pushEvent("set_count", { value: count + amount })}
>
+{amount}
</button>
</div>
<label>
Amount:
<input
onChange={(e) => setAmount(parseInt(e.target.value, 10))}
type="number"
className="rounded"
value={amount}
min="1"
/>
</label>
</div>
);
}