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

質問編集履歴

1

エラーを追記

2018/09/27 04:23

投稿

hiroakitajima
hiroakitajima

スコア27

title CHANGED
File without changes
body CHANGED
@@ -14,4 +14,21 @@
14
14
  console.log(lastInnerWidth);
15
15
  console.log(boxSize);
16
16
  });
17
+ ```
18
+ ```jsx
19
+ //TypeError: this.setState is not a functionになる
20
+ let map = document.getElementById("map");
21
+ var lastInnerWidth = map.clientWidth;
22
+ window.addEventListener("resize", function() {
23
+ if (lastInnerWidth != map.clientWidth) {
24
+ lastInnerWidth = map.clientWidth;
25
+ }
26
+ let boxSize = (lastInnerWidth - 100) / 5;
27
+ this.setState({
28
+ mapWidth: lastInnerWidth,
29
+ boxWidth: boxSize
30
+ });
31
+ console.log(this.state.mapWidth);
32
+ console.log(this.state.boxWidth);
33
+ });
17
34
  ```