回答編集履歴
1
追記
answer
CHANGED
@@ -2,8 +2,14 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
-
click() メソッド中の this
|
5
|
+
click() メソッド中の this は恐らく Window オブジェクトと差していると思います。
|
6
|
+
App コンポーネントのインスタンスそのものを差すようにするには以下のようにしてください。
|
6
7
|
|
7
8
|
```js
|
8
9
|
<h1 onClick={this.click.bind(this)}>Hello World</h1>
|
9
|
-
```
|
10
|
+
```
|
11
|
+
|
12
|
+
または、またはメソッドをアロー関数で定義することで避けられます。
|
13
|
+
|
14
|
+
[reactjs - this.setState is undefined - Stack Overflow](https://stackoverflow.com/questions/39210971/this-setstate-is-undefined)
|
15
|
+
[javascript - Unable to access React instance (this) inside event handler - Stack Overflow](https://stackoverflow.com/questions/29577977/unable-to-access-react-instance-this-inside-event-handler)
|