You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, just keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, simply take the length of the TODO items array.
Think of all of the pieces of data in our example application. We have:
88
+
今回のサンプルアプリを形作るデータについて考えてみましょう。次のようなデータがあります。
89
89
90
-
*The original list of products
91
-
*The search text the user has entered
92
-
*The value of the checkbox
93
-
*The filtered list of products
90
+
*元となる商品のリスト
91
+
*ユーザーが入力した検索文字列
92
+
*チェックボックスの値
93
+
*フィルタ済みの商品のリスト
94
94
95
-
Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data:
95
+
それぞれについて見ていき、どれが state になりうるのかを考えてみます。各データについて、 3 つの質問をするだけです。
96
96
97
-
1.Is it passed in from a parent via props? If so, it probably isn't state.
98
-
2.Does it remain unchanged over time? If so, it probably isn't state.
99
-
3.Can you compute it based on any other state or props in your component? If so, it isn't state.
97
+
1.親から props を通じて与えられたデータでしょうか? もしそうなら、それは state ではありません
98
+
2.時間経過で変化しないままでいるデータでしょうか? もしそうなら、それは state ではありません
99
+
3.コンポーネント内にある他の props や state を使って算出可能なデータでしょうか? もしそうなら、それは state ではありません
100
100
101
-
The original list of products is passed in as props, so that's not state. The search text and the checkbox seem to be state since they change over time and can't be computed from anything. And finally, the filtered list of products isn't state because it can be computed by combining the original list of products with the search text and value of the checkbox.
101
+
元となる商品のリストは props から渡されるので、これは state ではありません。検索文字列とチェックボックスは時間の経過の中で変化し、また、算出することもできないため、state だと思われます。最後に、フィルタ済みの商品のリストは state ではありません。何故ならば、元となる商品のリストと検索文字列とチェックボックスの値を組み合わせることで、フィルタ済みの商品のリストを算出することが可能だからです。
0 commit comments