Skip to content

Commit 79b503c

Browse files
authored
Merge pull request #352 from leduc1901/leduc1901/fragment
Translation: Fragment
2 parents 1335e38 + 0cf9a88 commit 79b503c

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/content/reference/react/Fragment.md

Lines changed: 21 additions & 21 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>`, hay còn được sử dụng với cú pháp `<>...</>`, cho phép bạn nhóm các phần tử mà không cần bọc chúng trong một node nào đó.
88

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

2020
---
2121

22-
## Reference {/*reference*/}
22+
## Tham khảo {/*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+
Để nhóm các phần tử lại với nhau trong các tình huống mà bạn cần một phần tử đơn, hãy bọc chúng trong thẻ `<Fragment>`. Nhóm các phần tử trong `Fragment` không ảnh hưởng đến DOM; DOM sẽ giống như khi các phần tử không được nhóm lại. Trong hầu hết các trường hợp Thẻ JSX rỗng `<></>` là cách viết tắt cho `<Fragment></Fragment>`.
2727

2828
#### 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` **tuỳ chọn** : Các Fragment được khai báo bằng cú pháp rõ ràng `<Fragment>` có thể có [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
3131

32-
#### Caveats {/*caveats*/}
32+
#### Những lưu ý {/*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>`.
34+
- Nếu bạn muốn truyền `key` vào một Fragment, bạn không thể sử dụng cú pháp `<>...</>`. Bạn phải import rõ ràng `Fragment` từ `'react'` render `<Fragment key={yourKey}>...</Fragment>`.
3535

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)
36+
- React không [đặt lại state](/learn/preserving-and-resetting-state) khi bản chuyển từ việc render `<><Child /></>` sang `[<Child />]` hay ngược lại, hoặc khi bạn chuyển từ render `<><Child /></>` sang `<Child />` và ngược lại. Điều này chỉ hoạt động chính xác ở mức độ một cấp: ví dụ, từ `<><><Child /></></>` sang `<Child />` sẽ đặt lại state. Xem cụ thể về cách hoạt động [ở đây.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
3737

3838
---
3939

40-
## Usage {/*usage*/}
40+
## Cách sử dụng {/*usage*/}
4141

42-
### Returning multiple elements {/*returning-multiple-elements*/}
42+
### Trả về nhiều phần tử {/*returning-multiple-elements*/}
4343

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:
44+
Sử dụng `Fragment`, hoặc cú pháp tương đương `<>...</>`, để nhóm các phần tử lại với nhau. Bạn có thể sử dụng Fragment để đặt nhiều phần tử vào bất kỳ nơi nào mà một phần tử đơn lẻ có thể được sử dụng. Ví dụ, một thành phần chỉ có thể trả về một phần tử, nhưng bằng cách sử dụng Fragment, bạn có thể nhóm nhiều phần tử lại với nhau và sau đó trả về chúng như một nhóm.:
4545

4646
```js {3,6}
4747
function Post() {
@@ -54,7 +54,7 @@ function Post() {
5454
}
5555
```
5656

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:
57+
Fragments rất hữu ích vì nhóm các phần tử với một Fragment không ảnh hưởng đến bố cục hay cách các phần tử hiển thị, khác với khi bạn bọc các phần tử trong một container khác như một DOM element. Nếu bạn kiểm tra ví dụ này với các công cụ trình duyệt, bạn sẽ thấy tất cả các nút DOM `<h1>` `<article>` xuất hiện như là các sibling mà không có các wrapper xung quanh chúng:
5858

5959
<Sandpack>
6060

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

9595
<DeepDive>
9696

97-
#### How to write a Fragment without the special syntax? {/*how-to-write-a-fragment-without-the-special-syntax*/}
97+
#### Làm thế nào để viết Fragment mà không cần cú pháp đặc biệt? {/*how-to-write-a-fragment-without-the-special-syntax*/}
9898

99-
The example above is equivalent to importing `Fragment` from React:
99+
Câu ví dụ trên tương đương với việc import `Fragment` từ React:
100100

101101
```js {1,5,8}
102102
import { Fragment } from 'react';
@@ -111,15 +111,15 @@ function Post() {
111111
}
112112
```
113113

114-
Usually you won't need this unless you need to [pass a `key` to your `Fragment`.](#rendering-a-list-of-fragments)
114+
Thông thường bạn sẽ không cần phải làm thế này trừ khi bạn cần [truyền `key` vào `Fragment`.](#rendering-a-list-of-fragments)
115115

116116
</DeepDive>
117117

118118
---
119119

120-
### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/}
120+
### Gán nhiều phần tử vào một biến {/*assigning-multiple-elements-to-a-variable*/}
121121

122-
Like any other element, you can assign Fragment elements to variables, pass them as props, and so on:
122+
Như mọi phần tử khác, bạn có thể gán các phần tử Fragment vào các biến, truyền chúng như props, và hơn thế nữa:
123123

124124
```js
125125
function CloseDialog() {
@@ -139,9 +139,9 @@ function CloseDialog() {
139139
140140
---
141141
142-
### Grouping elements with text {/*grouping-elements-with-text*/}
142+
### Nhóm các phần tử với văn bản {/*grouping-elements-with-text*/}
143143
144-
You can use `Fragment` to group text together with components:
144+
Bạn có thể dùng `Fragment` để nhóm các văn bản với các thành phần:
145145
146146
```js
147147
function DateRangePicker({ start, end }) {
@@ -158,9 +158,9 @@ function DateRangePicker({ start, end }) {
158158
159159
---
160160
161-
### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/}
161+
### Hiển thị một danh sách gồm các Fragment {/*rendering-a-list-of-fragments*/}
162162
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:
163+
Dưới đây là một trường hợp mà bạn cần viết `Fragment` một cách rõ ràng thay vì sử dụng cú pháp `<></>`. Khi bạn [render nhiều phần tử trong một vòng lặp](/learn/rendering-lists), bạn cần gán một `key` cho mỗi phần tử. Nếu các phần tử trong vòng lặp là Fragments, bạn cần sử dụng cú pháp JSX thông thường để cung cấp thuộc tính `key`:
164164
165165
```js {3,6}
166166
function Blog() {
@@ -173,7 +173,7 @@ function Blog() {
173173
}
174174
```
175175
176-
You can inspect the DOM to verify that there are no wrapper elements around the Fragment children:
176+
Bạn có thể kiểm tra DOM để xác nhận rằng không có phần tử bao quanh các phần tử con của Fragmen:
177177
178178
<Sandpack>
179179

0 commit comments

Comments
 (0)