teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2020/04/15 04:14

投稿

hoshi-takanori
hoshi-takanori

スコア7903

answer CHANGED
@@ -9,4 +9,27 @@
9
9
 
10
10
  // Props が空の場合は、<Props> は省略できます。
11
11
  const Btn: React.FC = () => { ... };
12
+ ```
13
+
14
+ ---
15
+
16
+ えっと、Props の型はこんな感じですよね。
17
+
18
+ ```TypeScript
19
+ interface Props {
20
+ text: string;
21
+ onClickFunction: (e: React.MouseEvent<HTMLButtonElement>) => void;
22
+ };
23
+ ```
24
+
25
+ これで行けませんか?
26
+
27
+ ```TypeScript
28
+ const Btn: React.FC<Props> = ({ text, onClickFunction }) => {
29
+ return (
30
+ <button onClick={onClickFunction} className="btn">
31
+ {text}
32
+ </button>
33
+ );
34
+ };
12
35
  ```

1

セミコロンを追加

2020/04/15 04:14

投稿

hoshi-takanori
hoshi-takanori

スコア7903

answer CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  ```TypeScript
4
4
  // React.FC<P> は (props: P) => JSX.Element|その他いろいろ という型です。
5
- const Btn: React.FC<Props> = (props) => { ... }
5
+ const Btn: React.FC<Props> = (props) => { ... };
6
6
 
7
7
  // props は使わずに、各要素を分割代入するのがお勧めです。
8
- const Btn: React.FC<Props> = ({ x, y, z }) => { ... }
8
+ const Btn: React.FC<Props> = ({ x, y, z }) => { ... };
9
9
 
10
10
  // Props が空の場合は、<Props> は省略できます。
11
- const Btn: React.FC = () => { ... }
11
+ const Btn: React.FC = () => { ... };
12
12
  ```