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

回答編集履歴

1

追記

2018/07/11 06:49

投稿

og24715
og24715

スコア832

answer CHANGED
@@ -2,8 +2,14 @@
2
2
 
3
3
  ---
4
4
 
5
- click() メソッド中の this Appラスをさないので以下のようにしてくださ
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)