回答編集履歴
4
https://www.npmjs.com/package/prop-types
answer
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
```
|
8
8
|
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
9
9
|
|
10
|
+
[https://www.npmjs.com/package/prop-types
|
11
|
+
](https://www.npmjs.com/package/prop-types)
|
10
12
|
詳しくは公式ドキュメントを参照してください。
|
11
13
|
[https://reactjs.org/docs/context.html
|
12
14
|
](https://reactjs.org/docs/context.html)
|
3
あ
answer
CHANGED
@@ -8,4 +8,33 @@
|
|
8
8
|
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
9
9
|
|
10
10
|
詳しくは公式ドキュメントを参照してください。
|
11
|
-
https://reactjs.org/docs/context.html
|
11
|
+
[https://reactjs.org/docs/context.html
|
12
|
+
](https://reactjs.org/docs/context.html)
|
13
|
+
# 補足
|
14
|
+
|
15
|
+
> ここでApp.childContextTypesをどこに記述すれば良いかわかりませんでした……
|
16
|
+
|
17
|
+
```
|
18
|
+
class App extends React.Component {
|
19
|
+
getChildContext() {
|
20
|
+
return { shortcuts: shortcutManager }
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
App.childContextTypes = {
|
25
|
+
shortcuts: PropTypes.object.isRequired
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
既に適切な場所に記述出来ています。これはこれで正しいです。
|
30
|
+
|
31
|
+
```
|
32
|
+
class App extends React.Component {
|
33
|
+
static childContextTypes = {
|
34
|
+
shortcuts: React.PropTypes.object.isRequired
|
35
|
+
}
|
36
|
+
}
|
37
|
+
```
|
38
|
+
ただ、公式のデモコードを見ると、このような書き方をしていると思います。
|
39
|
+
これがもう1つの質問の方にも投稿されていた内容と関連する、[Class Fieldシンタックス](https://github.com/tc39/proposal-class-fields)です。
|
40
|
+
こういった書き方も可能です。
|
2
goji
answer
CHANGED
@@ -7,5 +7,5 @@
|
|
7
7
|
```
|
8
8
|
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
9
9
|
|
10
|
-
詳しくは公式ドキュメントを参照し
|
10
|
+
詳しくは公式ドキュメントを参照してください。
|
11
11
|
https://reactjs.org/docs/context.html
|
1
あ
answer
CHANGED
@@ -5,4 +5,7 @@
|
|
5
5
|
```
|
6
6
|
import PropTypes from 'prop-types';
|
7
7
|
```
|
8
|
-
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
8
|
+
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
9
|
+
|
10
|
+
詳しくは公式ドキュメントを参照したください。
|
11
|
+
https://reactjs.org/docs/context.html
|