` シンタックス](/reference/react/Fragment#rendering-a-list-of-fragments)を使用する必要があります:
```js
import { Fragment } from 'react';
@@ -393,46 +393,46 @@ const listItems = people.map(person =>
);
```
-Fragments disappear from the DOM, so this will produce a flat list of ``, `
`, `
`, `
`, and so on.
+フラグメントは DOM から消え去るため、これにより `
`、`
`、`
`、`
` というように続くフラットなリストが生成されます。
-### Where to get your `key` {/*where-to-get-your-key*/}
+### `key` をどこから得るのか {/*where-to-get-your-key*/}
-Different sources of data provide different sources of keys:
+データソースの種類によって key を得る方法は異なります。
-* **Data from a database:** If your data is coming from a database, you can use the database keys/IDs, which are unique by nature.
-* **Locally generated data:** If your data is generated and persisted locally (e.g. notes in a note-taking app), use an incrementing counter, [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID) or a package like [`uuid`](https://www.npmjs.com/package/uuid) when creating items.
+* **データベースからのデータ:** データがデータベースから来る場合、データベースのキーや ID は必然的に一意ですので、それを利用できます。
+* **ローカルで生成されたデータ:** データがローカルで生成されて保持される場合(例:ノートを取るアプリにおけるノート)は、アイテムを作成する際に、インクリメンタルなカウンタや [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)、または [`uuid`](https://www.npmjs.com/package/uuid) などのパッケージを使用します。
-### Rules of keys {/*rules-of-keys*/}
+### `key` のルール {/*rules-of-keys*/}
-* **Keys must be unique among siblings.** However, it’s okay to use the same keys for JSX nodes in _different_ arrays.
-* **Keys must not change** or that defeats their purpose! Don't generate them while rendering.
+* **キーは兄弟間で一意でなければなりません。** ただし、*異なる*配列に対応する JSX ノードには同じキーを使用することができます。
+* **キーは変更してはいけません。** さもないと `key` の目的が台無しになります。レンダーの最中に key を生成してはいけません。
-### Why does React need keys? {/*why-does-react-need-keys*/}
+### なぜ React は `key` を必要とするのか {/*why-does-react-need-keys*/}
-Imagine that files on your desktop didn't have names. Instead, you'd refer to them by their order -- the first file, the second file, and so on. You could get used to it, but once you delete a file, it would get confusing. The second file would become the first file, the third file would be the second file, and so on.
+デスクトップ上のファイルに名前がない場合を想像してください。代わりに、最初のファイル、2 番目のファイルといったように、順番によってそれらを区別する必要があるとしましょう。そのうち番号に慣れるかもしれませんが、ファイルを削除した途端に混乱してしまいます。2 番目のファイルが 1 番目のファイルになり、3 番目のファイルが 2 番目のファイルになり、という具合です。
-File names in a folder and JSX keys in an array serve a similar purpose. They let us uniquely identify an item between its siblings. A well-chosen key provides more information than the position within the array. Even if the _position_ changes due to reordering, the `key` lets React identify the item throughout its lifetime.
+フォルダ内のファイル名と JSX の key の目的は似ています。兄弟間で項目を一意に識別できるようにするのです。適切に選択された key は、配列内の位置よりも多くの情報を提供します。並べ替えによって*位置*が変更されたとしても、`key` のおかげで React はその項目が存在する限り、それを一意に識別できるのです。
-You might be tempted to use an item's index in the array as its key. In fact, that's what React will use if you don't specify a `key` at all. But the order in which you render items will change over time if an item is inserted, deleted, or if the array gets reordered. Index as a key often leads to subtle and confusing bugs.
+アイテムのインデックスを `key` として使用したくなるかもしれません。実際、`key` を指定しなかった場合、React はデフォルトでインデックスを使用します。しかし、アイテムが挿入されたり削除されたり、配列を並び替えたりすると、レンダーするアイテムの順序も変わります。インデックスをキーとして利用すると、微妙かつややこしいバグの原因となります。
-Similarly, do not generate keys on the fly, e.g. with `key={Math.random()}`. This will cause keys to never match up between renders, leading to all your components and DOM being recreated every time. Not only is this slow, but it will also lose any user input inside the list items. Instead, use a stable ID based on the data.
+同様に、`key={Math.random()}` などとしてキーをその場で生成してはいけません。こうするとキーがレンダーごとに一切合致しなくなり、コンポーネントと DOM が毎回再作成されるようになります。これは遅くなるのみならず、リストアイテム内のユーザによる入力値も失われてしまいます。代わりに、データに紐づいた安定した ID を使用してください。
-Note that your components won't receive `key` as a prop. It's only used as a hint by React itself. If your component needs an ID, you have to pass it as a separate prop: ``.
+コンポーネントは `key` を props として受け取らないということに注意してください。React 自体がヒントとして使用するだけです。コンポーネントが ID を必要とする場合は、別の props として渡す必要があります:``。
-On this page you learned:
+このページでは以下のことを学びました:
-* How to move data out of components and into data structures like arrays and objects.
-* How to generate sets of similar components with JavaScript's `map()`.
-* How to create arrays of filtered items with JavaScript's `filter()`.
-* Why and how to set `key` on each component in a collection so React can keep track of each of them even if their position or data changes.
+* コンポーネントからデータを配列やオブジェクトといったデータ構造に移動する方法。
+* JavaScript の `map()` を使用して類似したコンポーネントの集まりを作成する方法。
+* JavaScript の `filter()` を使用してフィルタリングされたアイテムの配列を作成する方法。
+* コレクション内の各コンポーネントに `key` を設定して、位置やデータが変更された場合でも React がそれぞれを追跡できるようにする方法と、それが必要な理由。
@@ -440,11 +440,11 @@ On this page you learned:
-#### Splitting a list in two {/*splitting-a-list-in-two*/}
+#### リストを 2 つに分割する {/*splitting-a-list-in-two*/}
-This example shows a list of all people.
+この例では、すべての人物の一覧を表示しています。
-Change it to show two separate lists one after another: **Chemists** and **Everyone Else.** Like previously, you can determine whether a person is a chemist by checking if `person.profession === 'chemist'`.
+それを、**化学者 (chemist)** と **その他の人** の 2 つの別々の一覧に変更してください。前に述べたように、`person.profession === 'chemist'` であるかどうかを確認することで、その人が化学者であるかどうかを決定できます。
@@ -535,7 +535,7 @@ img { width: 100px; height: 100px; border-radius: 50%; }
-You could use `filter()` twice, creating two separate arrays, and then `map` over both of them:
+`filter()` を 2 回使用して、2 つの別々の配列を作成し、その両方に `map` を適用します。
@@ -648,9 +648,9 @@ img { width: 100px; height: 100px; border-radius: 50%; }
-In this solution, the `map` calls are placed directly inline into the parent `` elements, but you could introduce variables for them if you find that more readable.
+この解答では、`map` コールは親の `` 要素の中に直接インラインで配置されていますが、このための変数を導入する方が読みやすいと思った場合は、そうしても構いません。
-There is still a bit duplication between the rendered lists. You can go further and extract the repetitive parts into a `` component:
+レンダーされた 2 つのリストの間にはまだ少し重複部分があります。さらに進んで、反復部分を `` コンポーネントに抽出できます。
@@ -762,9 +762,9 @@ img { width: 100px; height: 100px; border-radius: 50%; }
-A very attentive reader might notice that with two `filter` calls, we check each person's profession twice. Checking a property is very fast, so in this example it's fine. If your logic was more expensive than that, you could replace the `filter` calls with a loop that manually constructs the arrays and checks each person once.
+注意深い方は、2 つの `filter` コールで各人物の職業を 2 回確認していることに気づくかもしれません。プロパティのチェックは非常に高速ですので、この例では問題ありません。あなたのロジックがそれ以上に重たい場合は、`filter` コールを手動のループに置き換え、各人物を一度だけチェックしながらループ内で手動で 2 つの配列を構築することができます。
-In fact, if `people` never change, you could move this code out of your component. From React's perspective, all that matters is that you give it an array of JSX nodes in the end. It doesn't care how you produce that array:
+実際、`people` が一切変わらないのであれば、このコードをコンポーネントの外に移動しても構いません。React の観点からは、最終的に JSX ノードの配列が生成されていればよいのです。どのようにしてその配列を生成しているかは問題ではありません:
@@ -882,13 +882,13 @@ img { width: 100px; height: 100px; border-radius: 50%; }
-#### Nested lists in one component {/*nested-lists-in-one-component*/}
+#### 同一コンポーネント内のネストしたリスト {/*nested-lists-in-one-component*/}
-Make a list of recipes from this array! For each recipe in the array, display its name as an `` and list its ingredients in a ``.
+以下の配列から、レシピのリストを作成してください! 配列内の各レシピについて、名前を `` で表示し、その材料を `` を使って表示してください。
-This will require nesting two different `map` calls.
+これには 2 つの異なる `map` コールをネストする必要があります。
@@ -926,7 +926,7 @@ export const recipes = [{
-Here is one way you could go about it:
+以下が解決法のひとつです:
@@ -972,13 +972,13 @@ export const recipes = [{
-Each of the `recipes` already includes an `id` field, so that's what the outer loop uses for its `key`. There is no ID you could use to loop over ingredients. However, it's reasonable to assume that the same ingredient won't be listed twice within the same recipe, so its name can serve as a `key`. Alternatively, you could change the data structure to add IDs, or use index as a `key` (with the caveat that you can't safely reorder ingredients).
+`recipes` の各要素にはすでに `id` フィールドが含まれているので、外側のループではこれを `key` として使用します。一方で材料をループするために使用できる ID はありません。しかし、同じレシピに同じ材料が 2 度表示されることはないと考えるのが妥当ですので、材料の名前を `key` として使用することができます。あるいは、データ構造を変更して ID を追加するか、インデックスを `key` として使用することもできます(ただし、材料を安全に並べ替えることはできなくなります)。
-#### Extracting a list item component {/*extracting-a-list-item-component*/}
+#### リスト要素のコンポーネントを抽出 {/*extracting-a-list-item-component*/}
-This `RecipeList` component contains two nested `map` calls. To simplify it, extract a `Recipe` component from it which will accept `id`, `name`, and `ingredients` props. Where do you place the outer `key` and why?
+この `RecipeList` コンポーネントは、2 つのネストした `map` 呼び出しを含んでいます。これを単純化するために、`id`, `name`, `ingredients` という props を受けとる `Recipe` コンポーネントを抽出してください。外側の `key` はどこに置きますか、またその理由は?
@@ -1026,7 +1026,7 @@ export const recipes = [{
-You can copy-paste the JSX from the outer `map` into a new `Recipe` component and return that JSX. Then you can change `recipe.name` to `name`, `recipe.id` to `id`, and so on, and pass them as props to the `Recipe`:
+外側の `map` から新しい `Recipe` コンポーネントに JSX をコピーペーストして、その JSX を返すことができます。そして、`recipe.name` を `name` に、`recipe.id` を `id` に変更し、`Recipe` に props として渡します:
@@ -1078,15 +1078,15 @@ export const recipes = [{
-Here, `` is a syntax shortcut saying "pass all properties of the `recipe` object as props to the `Recipe` component". You could also write each prop explicitly: ``.
+ここで `` というのは「 `recipe` オブジェクトのすべてのプロパティを `Recipe` コンポーネントの props として渡せ」という意味のショートカット構文です。個々の props を明示的に書いても構いません:``
-**Note that the `key` is specified on the `` itself rather than on the root `` returned from `Recipe`.** This is because this `key` is needed directly within the context of the surrounding array. Previously, you had an array of `
`s so each of them needed a `key`, but now you have an array of `
`s. In other words, when you extract a component, don't forget to leave the `key` outside the JSX you copy and paste.
+**`key` は `` から返される `` 内ではなく、`
` 自体に指定する必要があることに注意してください。** これは、`key` を直接必要としているのはそれを囲んでいる配列という文脈だからです。これまでは `` の配列があったので個々の div に `key` が必要でしたが、今存在するのは `
` の配列です。別の言い方をすると、コンポーネントを抽出する場合は、コピーペーストする JSX の外に `key` を残すことを忘れないようにしましょう。
-#### List with a separator {/*list-with-a-separator*/}
+#### セパレータ付きリスト {/*list-with-a-separator*/}
-This example renders a famous haiku by Katsushika Hokusai, with each line wrapped in a `` tag. Your job is to insert an `
` separator between each paragraph. Your resulting structure should look like this:
+この例では、葛飾北斎の有名な俳句を、各行を `` タグで囲みつつ表示しています。あなたの仕事は、各段落の間に `
` という区切り線を挿入することです。結果はこのような形にしてください。
```js
@@ -1098,7 +1098,7 @@ This example renders a famous haiku by Katsushika Hokusai, with each line wrappe
```
-A haiku only contains three lines, but your solution should work with any number of lines. Note that `
` elements only appear *between* the `` elements, not in the beginning or the end!
+俳句は 3 行しかありませんが、あなたの答えはどのような行数であっても動作するようにしてください。`
` 要素は `` 要素の*間*にのみ現れ、最初や最後には現れないことに注意してください!
@@ -1141,17 +1141,17 @@ hr {
-(This is a rare case where index as a key is acceptable because a poem's lines will never reorder.)
+(俳句の行が途中で入れ替わることは決してないので、今回は特例としてインデックスを key として利用して構いません。)
-You'll either need to convert `map` to a manual loop, or use a fragment.
+`map` を手動のループに置き換えるか、フラグメントを使う必要があります。
-You can write a manual loop, inserting `
` and `...
` into the output array as you go:
+手動でループを書いて、`
` と `...
` を出力用の配列に順番に入れていくという方法がとれます。
@@ -1206,9 +1206,9 @@ hr {
-Using the original line index as a `key` doesn't work anymore because each separator and paragraph are now in the same array. However, you can give each of them a distinct key using a suffix, e.g. `key={i + '-text'}`.
+各セパレータと段落は同じ配列に入るので、元の行インデックスを `key` として使用することはできなくなります。ですが `key={i + '-text'}` のように後ろに文字を付加することで、一意なキーを与えることができます。
-Alternatively, you could render a collection of fragments which contain `
` and `...
`. However, the `<>...>` shorthand syntax doesn't support passing keys, so you'd have to write `` explicitly:
+あるいは、`
` と `...
` を含むフラグメントの配列をレンダーすることもできます。しかし、`<>...>` という省略記法は key を渡すことをサポートしていないため、明示的に `` と記述する必要があります:
@@ -1254,7 +1254,7 @@ hr {
-Remember, fragments (often written as `<> >`) let you group JSX nodes without adding extra ``s!
+フラグメント(通常は `<> >` のように書かれる)によって、余分な `
` を増やさずに JSX ノードをグループ化できるということを覚えておきましょう!
diff --git a/src/sidebarLearn.json b/src/sidebarLearn.json
index f3d5e5dfe..ba8b4e613 100644
--- a/src/sidebarLearn.json
+++ b/src/sidebarLearn.json
@@ -47,7 +47,7 @@
"sectionHeader": "LEARN REACT"
},
{
- "title": "Describing the UI",
+ "title": "UI の記述",
"tags": [],
"path": "/learn/describing-the-ui",
"routes": [
@@ -72,15 +72,15 @@
"path": "/learn/passing-props-to-a-component"
},
{
- "title": "Conditional Rendering",
+ "title": "条件付きレンダー",
"path": "/learn/conditional-rendering"
},
{
- "title": "Rendering Lists",
+ "title": "リストのレンダー",
"path": "/learn/rendering-lists"
},
{
- "title": "Keeping Components Pure",
+ "title": "コンポーネントを純粋に保つ",
"path": "/learn/keeping-components-pure"
}
]