From c9a8b49554ef3d7e87492557be2d649f7c34fff9 Mon Sep 17 00:00:00 2001 From: Duc Le Date: Fri, 28 Apr 2023 14:33:18 +0700 Subject: [PATCH 1/2] Translation: Fragment --- src/content/reference/react/Fragment.md | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/content/reference/react/Fragment.md b/src/content/reference/react/Fragment.md index 638450405..9977ca8c2 100644 --- a/src/content/reference/react/Fragment.md +++ b/src/content/reference/react/Fragment.md @@ -4,7 +4,7 @@ title: (<>...) -``, often used via `<>...` syntax, lets you group elements without a wrapper node. +``, 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 đó. ```js <> @@ -19,29 +19,29 @@ title: (<>...) --- -## Reference {/*reference*/} +## Tham khảo {/*tham-khảo*/} ### `` {/*fragment*/} -Wrap elements in `` 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 `` in most cases. +Để 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ẻ ``. 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 ``. #### Props {/*props*/} -- **optional** `key`: Fragments declared with the explicit `` syntax may have [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key) +- `key` **tuỳ chọn** : Các Fragment được khai báo bằng cú pháp rõ ràng `` có thể có [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key) -#### Caveats {/*caveats*/} +#### Những lưu ý {/*những-lưu-ý*/} -- 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 `...`. +- 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'` và render `...`. -- React does not [reset state](/learn/preserving-and-resetting-state) when you go from rendering `<>` to `[]` or back, or when you go from rendering `<>` to `` and back. This only works a single level deep: for example, going from `<><>` to `` resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b) +- React không [đặt lại state](/learn/preserving-and-resetting-state) khi bản chuyển từ việc render `<>` sang `[]` hay ngược lại, hoặc khi bạn chuyển từ render `<>` sang `` 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ừ `<><>` sang `` sẽ đặt lại state. Xem cụ thể về cách hoạt động [ở đây.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b) --- -## Usage {/*usage*/} +## Cách sử dụng {/*cách-sử-dụng*/} -### Returning multiple elements {/*returning-multiple-elements*/} +### Trả về nhiều phần tử {/*trả-về-nhiều-phần-tử*/} -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: +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.: ```js {3,6} function Post() { @@ -54,7 +54,7 @@ function Post() { } ``` -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 `

` and `

` DOM nodes appear as siblings without wrappers around them: +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 `

` và `

` xuất hiện như là các sibling mà không có các wrapper xung quanh chúng: @@ -94,9 +94,9 @@ function PostBody({ body }) { -#### How to write a Fragment without the special syntax? {/*how-to-write-a-fragment-without-the-special-syntax*/} +#### Làm thế nào để viết Fragment mà không cần cú pháp đặc biệt? {/*làm-thế-nào-để-viết-fragment-mà-không-cần-cú-pháp-đặc-biệt*/} -The example above is equivalent to importing `Fragment` from React: +Câu ví dụ trên tương đương với việc import `Fragment` từ React: ```js {1,5,8} import { Fragment } from 'react'; @@ -111,15 +111,15 @@ function Post() { } ``` -Usually you won't need this unless you need to [pass a `key` to your `Fragment`.](#rendering-a-list-of-fragments) +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) --- -### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/} +### Gán nhiều phần tử vào một biến {/*gán-nhiều-phần-tử-vào-một-biến*/} -Like any other element, you can assign Fragment elements to variables, pass them as props, and so on: +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: ```js function CloseDialog() { @@ -139,9 +139,9 @@ function CloseDialog() { --- -### Grouping elements with text {/*grouping-elements-with-text*/} +### Nhóm các phần tử với văn bản {/*nhóm-các-phần-tử-với-văn-bản*/} -You can use `Fragment` to group text together with components: +Bạn có thể dùng `Fragment` để nhóm các văn bản với các thành phần: ```js function DateRangePicker({ start, end }) { @@ -158,9 +158,9 @@ function DateRangePicker({ start, end }) { --- -### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/} +### Hiển thị một danh sách gồm các Fragment {/*rendering-a-list-of-fragments*/} -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: +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`: ```js {3,6} function Blog() { @@ -173,7 +173,7 @@ function Blog() { } ``` -You can inspect the DOM to verify that there are no wrapper elements around the Fragment children: +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: From c125f00b037d796311d2e79a4ced624091bc93da Mon Sep 17 00:00:00 2001 From: Duc Le Date: Fri, 28 Apr 2023 17:03:12 +0700 Subject: [PATCH 2/2] revert heading id --- src/content/reference/react/Fragment.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/content/reference/react/Fragment.md b/src/content/reference/react/Fragment.md index 9977ca8c2..3c07c29ef 100644 --- a/src/content/reference/react/Fragment.md +++ b/src/content/reference/react/Fragment.md @@ -19,7 +19,7 @@ title: (<>...) --- -## Tham khảo {/*tham-khảo*/} +## Tham khảo {/*reference*/} ### `` {/*fragment*/} @@ -29,7 +29,7 @@ title: (<>...) - `key` **tuỳ chọn** : Các Fragment được khai báo bằng cú pháp rõ ràng `` có thể có [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key) -#### Những lưu ý {/*những-lưu-ý*/} +#### Những lưu ý {/*caveats*/} - 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'` và render `...`. @@ -37,9 +37,9 @@ title: (<>...) --- -## Cách sử dụng {/*cách-sử-dụng*/} +## Cách sử dụng {/*usage*/} -### Trả về nhiều phần tử {/*trả-về-nhiều-phần-tử*/} +### Trả về nhiều phần tử {/*returning-multiple-elements*/} 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.: @@ -94,7 +94,7 @@ function PostBody({ body }) { -#### Làm thế nào để viết Fragment mà không cần cú pháp đặc biệt? {/*làm-thế-nào-để-viết-fragment-mà-không-cần-cú-pháp-đặc-biệt*/} +#### 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*/} Câu ví dụ trên tương đương với việc import `Fragment` từ React: @@ -117,7 +117,7 @@ Thông thường bạn sẽ không cần phải làm thế này trừ khi bạn --- -### Gán nhiều phần tử vào một biến {/*gán-nhiều-phần-tử-vào-một-biến*/} +### Gán nhiều phần tử vào một biến {/*assigning-multiple-elements-to-a-variable*/} 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: @@ -139,7 +139,7 @@ function CloseDialog() { --- -### Nhóm các phần tử với văn bản {/*nhóm-các-phần-tử-với-văn-bản*/} +### Nhóm các phần tử với văn bản {/*grouping-elements-with-text*/} Bạn có thể dùng `Fragment` để nhóm các văn bản với các thành phần: