-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern2Demo.tsx
More file actions
40 lines (36 loc) · 946 Bytes
/
Pattern2Demo.tsx
File metadata and controls
40 lines (36 loc) · 946 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
39
40
import { useState } from "react";
import { Dialog, DialogTrigger, DialogContent, DialogTitle } from "./ui/Dialog";
type Props = {
initialValue: number;
};
export const Pattern2Demo: React.FC<Props> = (props) => {
return (
<Dialog>
<DialogTrigger asChild>
<button className="px-4 py-2 bg-green-400 text-white rounded">
Pattern 2 (State揮発)
</button>
</DialogTrigger>
<DialogContent>
<Content {...props} />
</DialogContent>
</Dialog>
);
};
const Content: React.FC<Props> = ({ initialValue }) => {
const [count, setCount] = useState(initialValue);
return (
<>
<DialogTitle>Pattern 2</DialogTitle>
<div className="flex gap-2 items-center">
<button
className="size-8 border rounded"
onClick={() => setCount(count + 1)}
>
+
</button>
<span>Count: {count}</span>
</div>
</>
);
};