Skip to content

Commit bb8d618

Browse files
committed
docs(thinking-in-react): Thinking in React - Step 4
1 parent f287a6f commit bb8d618

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

content/docs/thinking-in-react.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@ UI をインタラクティブなものにするにあたり、UIを構築する
105105
* ユーザーが入力した検索文字列
106106
* チェックボックスの値
107107

108-
## Step 4: Identify Where Your State Should Live
108+
## Step 4:state をどこに配置するべきなのかを明確にする
109109

110110
<p data-height="600" data-theme-id="0" data-slug-hash="qPrNQZ" data-default-tab="js" data-user="lacker" data-embed-version="2" class="codepen">See the Pen <a href="https://codepen.io/gaearon/pen/qPrNQZ">Thinking In React: Step 4</a> on <a href="http://codepen.io">CodePen</a>.</p>
111111

112-
OK, so we've identified what the minimal set of app state is. Next, we need to identify which component mutates, or *owns*, this state.
112+
さて、state の最小構成が明確になりました。次は、どのコンポーネントを変化させるのか、そして*どのコンポーネントが state を持つのか*を明確にしましょう。
113113

114-
Remember: React is all about one-way data flow down the component hierarchy. It may not be immediately clear which component should own what state. **This is often the most challenging part for newcomers to understand,** so follow these steps to figure it out:
114+
復習:React は、コンポーネントの階層構造をデータが下っていく、単方向データフローで成り立っています。もしかすると、どのコンポーネントがどんな state を持つべきなのかが、すぐにはわからないかもしれません。**これは、初学者がReactへの理解を深める上で、最も難しい問題になりがちなところ** なので、ステップを踏みながら理解していきましょう。
115115

116-
For each piece of state in your application:
116+
アプリの各 state について、次の各項目を確認していきます。
117117

118-
* Identify every component that renders something based on that state.
119-
* Find a common owner component (a single component above all the components that need the state in the hierarchy).
120-
* Either the common owner or another component higher up in the hierarchy should own the state.
121-
* If you can't find a component where it makes sense to own the state, create a new component simply for holding the state and add it somewhere in the hierarchy above the common owner component.
118+
* その state を使って表示を行う、すべてのコンポーネントを確認する
119+
* 共通の親コンポーネントを見つける(その階層構造の中で、ある state を必要としているすべてのコンポーネントの真上にある単一のコンポーネントのことです)
120+
* 共通の親コンポーネントか、その階層構造でさらに上位の別のコンポーネントが state を持っているべきである
121+
* もし state を持つにふさわしいコンポーネントを見つけられなかった場合は、state を保持するためのコンポーネントを作り、そこに state を置いた上で、階層構造の中ですでに見つけていた共通の親コンポーネントの上に配置する
122122

123-
Let's run through this strategy for our application:
123+
それでは、この戦術をサンプルアプリにも適用してみましょう。
124124

125-
* `ProductTable` needs to filter the product list based on state and `SearchBar` needs to display the search text and checked state.
126-
* The common owner component is `FilterableProductTable`.
127-
* It conceptually makes sense for the filter text and checked value to live in `FilterableProductTable`
125+
* `ProductTable` は商品リストをフィルタする必要があり、`SearchBar` は検索文字列とチェック状態を表示する必要がある
126+
* 共通の親コンポーネントは `FilterableProductTable` である
127+
* 概念的にも、検索文字列とチェック状態が `FilterableProductTable` に配置されることは妥当である
128128

129-
Cool, so we've decided that our state lives in `FilterableProductTable`. First, add an instance property `this.state = {filterText: '', inStockOnly: false}` to `FilterableProductTable`'s `constructor` to reflect the initial state of your application. Then, pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as a prop. Finally, use these props to filter the rows in `ProductTable` and set the values of the form fields in `SearchBar`.
129+
いいですね。 state `FilterableProductTable` の中に配置することが決まりました。では早速、インスタンス変数として `this.state = {filterText: '', inStockOnly: false}` `FilterableProductTable``constructor` に追加して、初期状態をアプリに反映しましょう。その次は、`filterText` `inStockOnly` `ProductTable` `SearchBar` に props として渡します。最後に、これらの props を使って `ProductTable` のフィルタ処理を行い、`SearchBar` のフォームにも値を埋めます。
130130

131-
You can start seeing how your application will behave: set `filterText` to `"ball"` and refresh your app. You'll see that the data table is updated correctly.
131+
これで、このアプリがどんな振る舞いをするのか見られるようになってきました。`filterText` `"ball"` と入力した状態でアプリを更新すると、データの表が正しく更新されたことが確認できるはずです。
132132

133133
## Step 5: Add Inverse Data Flow
134134

0 commit comments

Comments
 (0)