回答編集履歴
2
追記
test
CHANGED
@@ -21,3 +21,49 @@
|
|
21
21
|
const Btn: React.FC = () => { ... };
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
えっと、Props の型はこんな感じですよね。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```TypeScript
|
36
|
+
|
37
|
+
interface Props {
|
38
|
+
|
39
|
+
text: string;
|
40
|
+
|
41
|
+
onClickFunction: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
42
|
+
|
43
|
+
};
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
これで行けませんか?
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```TypeScript
|
54
|
+
|
55
|
+
const Btn: React.FC<Props> = ({ text, onClickFunction }) => {
|
56
|
+
|
57
|
+
return (
|
58
|
+
|
59
|
+
<button onClick={onClickFunction} className="btn">
|
60
|
+
|
61
|
+
{text}
|
62
|
+
|
63
|
+
</button>
|
64
|
+
|
65
|
+
);
|
66
|
+
|
67
|
+
};
|
68
|
+
|
69
|
+
```
|
1
セミコロンを追加
test
CHANGED
@@ -6,18 +6,18 @@
|
|
6
6
|
|
7
7
|
// React.FC<P> は (props: P) => JSX.Element|その他いろいろ という型です。
|
8
8
|
|
9
|
-
const Btn: React.FC<Props> = (props) => { ... }
|
9
|
+
const Btn: React.FC<Props> = (props) => { ... };
|
10
10
|
|
11
11
|
|
12
12
|
|
13
13
|
// props は使わずに、各要素を分割代入するのがお勧めです。
|
14
14
|
|
15
|
-
const Btn: React.FC<Props> = ({ x, y, z }) => { ... }
|
15
|
+
const Btn: React.FC<Props> = ({ x, y, z }) => { ... };
|
16
16
|
|
17
17
|
|
18
18
|
|
19
19
|
// Props が空の場合は、<Props> は省略できます。
|
20
20
|
|
21
|
-
const Btn: React.FC = () => { ... }
|
21
|
+
const Btn: React.FC = () => { ... };
|
22
22
|
|
23
23
|
```
|