Skip to content

Commit ec5ef4f

Browse files
committed
Translate Fragment
1 parent aff743b commit ec5ef4f

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/content/reference/react/Fragment.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: <Fragment> (<>...</>)
44

55
<Intro>
66

7-
`<Fragment>`, often used via `<>...</>` syntax, lets you group elements without a wrapper node.
7+
`<Fragment>` は頻繁に `<>...</>` 構文で使用され、ノードでラップせずに要素をグループ化することができます。
88

99
```js
1010
<>
@@ -19,29 +19,28 @@ title: <Fragment> (<>...</>)
1919

2020
---
2121

22-
## Reference {/*reference*/}
22+
## リファレンス {/*reference*/}
2323

2424
### `<Fragment>` {/*fragment*/}
2525

26-
Wrap elements in `<Fragment>` to group them together in situations where you need a single element. Grouping elements in `Fragment` has no effect on the resulting DOM; it is the same as if the elements were not grouped. The empty JSX tag `<></>` is shorthand for `<Fragment></Fragment>` in most cases.
26+
単一の要素が必要な場合は、`<Fragment>` でラップすると複数の要素をグループ化することができます。`Fragment` で要素をグループ化しても、出力される DOM には影響を与えません。要素がグループ化されていないときと同じです。空の JSX タグ `<></>` は、ほとんどの場合 `<Fragment></Fragment>` の省略記法です。
2727

28-
#### Props {/*props*/}
28+
#### props {/*props*/}
2929

30-
- **optional** `key`: Fragments declared with the explicit `<Fragment>` syntax may have [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
30+
- **省略可能** `key`: 明示的な `<Fragment>` 構文で宣言されたフラグメントは [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key) を持つことができます。
3131

32-
#### Caveats {/*caveats*/}
32+
#### 注意点 {/*caveats*/}
3333

34-
- If you want to pass `key` to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment` from `'react'` and render `<Fragment key={yourKey}>...</Fragment>`.
35-
36-
- React does not [reset state](/learn/preserving-and-resetting-state) when you go from rendering `<><Child /></>` to `[<Child />]` or back, or when you go from rendering `<><Child /></>` to `<Child />` and back. This only works a single level deep: for example, going from `<><><Child /></></>` to `<Child />` resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
34+
- `key` をフラグメントに渡したい場合は、`<>...</>` 構文を使用することはできません。`'react'` から `Fragment` を明示的にインポートし、`<Fragment key={yourKey}>...</Fragment>` をレンダーしなければなりません。
3735

36+
- React は、`<><Child /></>` のレンダーから `[<Child />]` に変更されるときか戻るとき、または `<><Child /></>` のレンダーから `<Child />` に変更されるときや戻るときは [state はリセット](/learn/preserving-and-resetting-state)されません。これは 1 つの階層のときのみ動作します:例えば、`<><><Child /></></>` から `<Child />` への変更は state がリセットされます。詳細なセマンティクス(semantics, 意味論)は[こちら](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)を参照してください。
3837
---
3938

40-
## Usage {/*usage*/}
39+
## 使用法 {/*usage*/}
4140

42-
### Returning multiple elements {/*returning-multiple-elements*/}
41+
### 複数の要素を返す {/*returning-multiple-elements*/}
4342

44-
Use `Fragment`, or the equivalent `<>...</>` syntax, to group multiple elements together. You can use it to put multiple elements in any place where a single element can go. For example, a component can only return one element, but by using a Fragment you can group multiple elements together and then return them as a group:
43+
複数の要素をグループ化するために `Fragment` や同等の `<>...</>` 構文を使用することができます。単一の要素が行き来できる場所ならどこでも、複数の要素を配置することができます。例えば、1 つのコンポーネントは 1 つの要素しか返すことができませんが、フラグメントを使用すれば複数の要素を一度にグループ化して、それらをグループとして返します。
4544

4645
```js {3,6}
4746
function Post() {
@@ -54,7 +53,7 @@ function Post() {
5453
}
5554
```
5655

57-
Fragments are useful because grouping elements with a Fragment has no effect on layout or styles, unlike if you wrapped the elements in another container like a DOM element. If you inspect this example with the browser tools, you'll see that all `<h1>` and `<article>` DOM nodes appear as siblings without wrappers around them:
56+
フラグメントは便利です。なぜなら、DOM 要素のような他のコンテナで要素をラップする場合と異なり、フラグメントで要素をグループ化してもレイアウトやスタイルに影響を与えないからです。この例を、ブラウザツールでインスペクト(inspect, 調査)してみると、全ての `<h1>` `<article>` DOM ノードがラップされずに兄弟として表示されることがわかります。
5857

5958
<Sandpack>
6059

@@ -94,9 +93,9 @@ function PostBody({ body }) {
9493

9594
<DeepDive>
9695

97-
#### How to write a Fragment without the special syntax? {/*how-to-write-a-fragment-without-the-special-syntax*/}
96+
#### 特別な構文を使わずに Fragment をどのように記述するか? {/*how-to-write-a-fragment-without-the-special-syntax*/}
9897

99-
The example above is equivalent to importing `Fragment` from React:
98+
上述の例は、React から `Fragment` をインポートすることと同じです:
10099

101100
```js {1,5,8}
102101
import { Fragment } from 'react';
@@ -111,15 +110,14 @@ function Post() {
111110
}
112111
```
113112

114-
Usually you won't need this unless you need to [pass a `key` to your `Fragment`.](#rendering-a-list-of-fragments)
115-
113+
通常なら [`Fragment``key` を渡す](#rendering-a-list-of-fragments) 場合以外では必要ありません。
116114
</DeepDive>
117115

118116
---
119117

120-
### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/}
118+
### 複数の要素を変数に割り当てる {/*assigning-multiple-elements-to-a-variable*/}
121119

122-
Like any other element, you can assign Fragment elements to variables, pass them as props, and so on:
120+
他の要素と同じように、フラグメントの要素を変数に割り当てたり、props として渡したりすることができます:
123121

124122
```js
125123
function CloseDialog() {
@@ -139,9 +137,9 @@ function CloseDialog() {
139137
140138
---
141139
142-
### Grouping elements with text {/*grouping-elements-with-text*/}
140+
### テキストと要素をグループ化する {/*grouping-elements-with-text*/}
143141
144-
You can use `Fragment` to group text together with components:
142+
`Fragment` を使うとテキストとコンポーネントを一度にグループ化することができます:
145143
146144
```js
147145
function DateRangePicker({ start, end }) {
@@ -158,9 +156,9 @@ function DateRangePicker({ start, end }) {
158156
159157
---
160158
161-
### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/}
159+
### Fragment のリストをレンダーする {/*rendering-a-list-of-fragments*/}
162160
163-
Here's a situation where you need to write `Fragment` explicitly instead of using the `<></>` syntax. When you [render multiple elements in a loop](/learn/rendering-lists), you need to assign a `key` to each element. If the elements within the loop are Fragments, you need to use the normal JSX element syntax in order to provide the `key` attribute:
161+
こちらは `<></>` 構文の代わりに `Fragment` を明示的に記述する必要がある場面です。ループ内で[複数の要素をレンダーする](/learn/rendering-lists)ときには、各要素に `key` を割り当てる必要があります。ループ内の要素がフラグメントの場合は、`key` 属性を提供するために通常の JSX 要素の構文を使用する必要があります。
164162
165163
```js {3,6}
166164
function Blog() {
@@ -173,7 +171,7 @@ function Blog() {
173171
}
174172
```
175173
176-
You can inspect the DOM to verify that there are no wrapper elements around the Fragment children:
174+
フラグメントの子要素のまわりにラッパー要素がないことを確認するために、DOM をインスペクトできます:
177175
178176
<Sandpack>
179177

0 commit comments

Comments
 (0)