回答編集履歴
4
https://www.npmjs.com/package/prop-types
test
CHANGED
@@ -15,6 +15,10 @@
|
|
15
15
|
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
16
16
|
|
17
17
|
|
18
|
+
|
19
|
+
[https://www.npmjs.com/package/prop-types
|
20
|
+
|
21
|
+
](https://www.npmjs.com/package/prop-types)
|
18
22
|
|
19
23
|
詳しくは公式ドキュメントを参照してください。
|
20
24
|
|
3
あ
test
CHANGED
@@ -18,4 +18,62 @@
|
|
18
18
|
|
19
19
|
詳しくは公式ドキュメントを参照してください。
|
20
20
|
|
21
|
-
https://reactjs.org/docs/context.html
|
21
|
+
[https://reactjs.org/docs/context.html
|
22
|
+
|
23
|
+
](https://reactjs.org/docs/context.html)
|
24
|
+
|
25
|
+
# 補足
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
> ここでApp.childContextTypesをどこに記述すれば良いかわかりませんでした……
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
class App extends React.Component {
|
36
|
+
|
37
|
+
getChildContext() {
|
38
|
+
|
39
|
+
return { shortcuts: shortcutManager }
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
App.childContextTypes = {
|
48
|
+
|
49
|
+
shortcuts: PropTypes.object.isRequired
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
既に適切な場所に記述出来ています。これはこれで正しいです。
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
class App extends React.Component {
|
64
|
+
|
65
|
+
static childContextTypes = {
|
66
|
+
|
67
|
+
shortcuts: React.PropTypes.object.isRequired
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
ただ、公式のデモコードを見ると、このような書き方をしていると思います。
|
76
|
+
|
77
|
+
これがもう1つの質問の方にも投稿されていた内容と関連する、[Class Fieldシンタックス](https://github.com/tc39/proposal-class-fields)です。
|
78
|
+
|
79
|
+
こういった書き方も可能です。
|
2
goji
test
CHANGED
@@ -16,6 +16,6 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
詳しくは公式ドキュメントを参照し
|
19
|
+
詳しくは公式ドキュメントを参照してください。
|
20
20
|
|
21
21
|
https://reactjs.org/docs/context.html
|
1
あ
test
CHANGED
@@ -13,3 +13,9 @@
|
|
13
13
|
```
|
14
14
|
|
15
15
|
context apiを使うには、prop-typesを使う必要があるので、prop-typesをインストール&インポートするのを忘れずに。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
詳しくは公式ドキュメントを参照したください。
|
20
|
+
|
21
|
+
https://reactjs.org/docs/context.html
|