-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter.tsx
More file actions
38 lines (32 loc) · 833 Bytes
/
counter.tsx
File metadata and controls
38 lines (32 loc) · 833 Bytes
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
"use client"
import { atom, useAtom } from "@lfades/atom"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"
const counterAtom = atom(0)
export function CounterExample() {
return (
<Card>
<CardContent className="p-6">
<div className="flex justify-center">
<Counter />
</div>
</CardContent>
</Card>
)
}
function Counter() {
const [count, setCount] = useAtom(counterAtom)
const increment = () => setCount(count + 1)
const decrement = () => setCount(count - 1)
return (
<div className="flex flex-col items-center gap-4">
<div className="text-4xl font-bold">{count}</div>
<div className="flex gap-2">
<Button onClick={decrement} variant="outline">
-
</Button>
<Button onClick={increment}>+</Button>
</div>
</div>
)
}