回答編集履歴

3

done

2018/03/07 08:52

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -121,7 +121,3 @@
121
121
  <component3 testFunc={this.func.bind(this} />
122
122
 
123
123
  ```
124
-
125
-
126
-
127
- # #5

2

a

2018/03/07 08:52

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- # 3
43
+ # #3
44
44
 
45
45
  ```
46
46
 
@@ -87,3 +87,41 @@
87
87
  }
88
88
 
89
89
  ```
90
+
91
+
92
+
93
+ #4
94
+
95
+ ```
96
+
97
+ <component3 testFunc={this.func} />
98
+
99
+ ```
100
+
101
+
102
+
103
+ あと、これですと以下のようなエラーが出てしまうかと思います。
104
+
105
+ ```
106
+
107
+ Cannot read property 'setState' of undefined
108
+
109
+ ```
110
+
111
+
112
+
113
+ なので、thisを適切にbindしてあげる必要があります。
114
+
115
+ いろいろやり方はありますが、とりあえず以下で。 
116
+
117
+
118
+
119
+ ```
120
+
121
+ <component3 testFunc={this.func.bind(this} />
122
+
123
+ ```
124
+
125
+
126
+
127
+ # #5

1

a

2018/03/07 08:51

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -37,3 +37,53 @@
37
37
  <component2 testProps={this.state} />
38
38
 
39
39
  ```
40
+
41
+
42
+
43
+ # 3
44
+
45
+ ```
46
+
47
+ this.state = (
48
+
49
+ hoge: false
50
+
51
+ );
52
+
53
+ ```
54
+
55
+ component1の上記部分ですが、これだと構文エラーが起きていませんか?
56
+
57
+
58
+
59
+ ```
60
+
61
+ state = {
62
+
63
+ hoge: false
64
+
65
+ }
66
+
67
+ ```
68
+
69
+
70
+
71
+ or
72
+
73
+
74
+
75
+ ```
76
+
77
+ constructor(props) {
78
+
79
+ super(props);
80
+
81
+ this.state = {
82
+
83
+ hoge: false
84
+
85
+ }
86
+
87
+ }
88
+
89
+ ```