質問編集履歴
4
連想配列
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
React : Stateに
|
1
|
+
React : Stateに連想配列を入れた場合の更新は差分でしょうか?
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
掲題の通りです。
|
2
|
-
以下のように、componentのstateに、buttonsというstateに
|
2
|
+
以下のように、componentのstateに、buttonsというstateに連想配列形式のデータを入れることを想定します。
|
3
3
|
この時、例えば`this.state.buttons["現在地"]`の`can_click`を、あるアクションを受けた場合`false`に変えるなどのfunctionを入れた場合、それが起きたら`<RadioCircleButtons buttons={buttons} />`の更新は
|
4
4
|
1. 差分(`this.state.buttons["現在地"].can_click`のみの更新)
|
5
5
|
2. すべて('this.state.buttons'を全て更新)
|
3
さらに追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,7 +43,11 @@
|
|
43
43
|
};
|
44
44
|
});
|
45
45
|
```
|
46
|
-
|
46
|
+
[https://teratail.com/questions/116344](https://teratail.com/questions/116344)
|
47
|
-
すごくヘビー
|
48
47
|
|
48
|
+
=== さらに追記 ===
|
49
|
-
[https://
|
49
|
+
[https://stackoverflow.com/questions/43040721/how-to-update-a-nested-state-in-react](https://stackoverflow.com/questions/43040721/how-to-update-a-nested-state-in-react)
|
50
|
+
ネストしたstateの書き換えについては理解しました。
|
51
|
+
|
52
|
+
依然として、ネストしたstateの更新が差分なのかはわかっていないので、ご教授いただきたいです。
|
53
|
+
追記が多くわかりづらくなってしまいましたが、よろしくお願いします。
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,4 +32,18 @@
|
|
32
32
|
export default DrillButtons;
|
33
33
|
```
|
34
34
|
|
35
|
-
よろしくお願いします。
|
35
|
+
よろしくお願いします。
|
36
|
+
|
37
|
+
==== 追記 ====
|
38
|
+
本質問と少し話がズレますが、
|
39
|
+
ネストしたcomponentを書き換えるには、全てを複製する必要がある??
|
40
|
+
```
|
41
|
+
this.setState({
|
42
|
+
buttons: { "現在地": { name: "現在地", can_click: false, is_selected: false }, "駅名": { name: "駅名", can_click: true, is_selected: false } },
|
43
|
+
};
|
44
|
+
});
|
45
|
+
```
|
46
|
+
上記のように、すべてをコピーしないといけないということでしょうか??
|
47
|
+
すごくヘビー
|
48
|
+
|
49
|
+
[https://teratail.com/questions/116344](https://teratail.com/questions/116344)
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
掲題の通りです。
|
2
2
|
以下のように、componentのstateに、buttonsというstateにハッシュ形式のデータを入れることを想定します。
|
3
|
-
この時、例えば`this.state.buttons`の`can_click`を、あるアクションを受けた場合`false`に変えるなどのfunctionを入れた場合、それが起きたら`<RadioCircleButtons buttons={buttons} />`の更新は
|
3
|
+
この時、例えば`this.state.buttons["現在地"]`の`can_click`を、あるアクションを受けた場合`false`に変えるなどのfunctionを入れた場合、それが起きたら`<RadioCircleButtons buttons={buttons} />`の更新は
|
4
4
|
1. 差分(`this.state.buttons["現在地"].can_click`のみの更新)
|
5
5
|
2. すべて('this.state.buttons'を全て更新)
|
6
6
|
|