You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/describing-the-ui.md
+56-56Lines changed: 56 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
1
---
2
-
title: Describing the UI
2
+
title: Mô tả UI
3
3
---
4
4
5
5
<Intro>
6
6
7
-
React is a JavaScript library for rendering user interfaces (UI). UI is built from small units like buttons, text, and images. React lets you combine them into reusable, nestable *components.* From web sites to phone apps, everything on the screen can be broken down into components. In this chapter, you'll learn to create, customize, and conditionally display React components.
7
+
React là một thư viện JavaScript để render giao diện người dùng (UI). UI được xây dựng từ những đơn vị nhỏ như nút bấm, văn bản và hình ảnh. React cho phép bạn kết hợp chúng thành những *component* có thể tái sử dụng và lồng ghép. Từ trang web đến ứng dụng điện thoại, mọi thứ trên màn hình đều có thể được chia nhỏ thành component. Trong chương này, bạn sẽ học cách tạo, tùy chỉnh và hiển thị React component theo điều kiện.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearnisChapter={true}>
12
12
13
-
*[How to write your first React component](/learn/your-first-component)
14
-
*[When and how to create multi-component files](/learn/importing-and-exporting-components)
15
-
*[How to add markup to JavaScript with JSX](/learn/writing-markup-with-jsx)
16
-
*[How to use curly braces with JSX to access JavaScript functionality from your components](/learn/javascript-in-jsx-with-curly-braces)
17
-
*[How to configure components with props](/learn/passing-props-to-a-component)
18
-
*[How to conditionally render components](/learn/conditional-rendering)
19
-
*[How to render multiple components at a time](/learn/rendering-lists)
20
-
*[How to avoid confusing bugs by keeping components pure](/learn/keeping-components-pure)
21
-
*[Why understanding your UI as trees is useful](/learn/understanding-your-ui-as-a-tree)
13
+
*[Cách viết React component đầu tiên của bạn](/learn/your-first-component)
14
+
*[Khi nào và cách tạo file multi-component](/learn/importing-and-exporting-components)
15
+
*[Cách thêm markup vào JavaScript với JSX](/learn/writing-markup-with-jsx)
16
+
*[Cách sử dụng dấu ngoặc nhọn với JSX để truy cập chức năng JavaScript từ component của bạn](/learn/javascript-in-jsx-with-curly-braces)
17
+
*[Cách cấu hình component với props](/learn/passing-props-to-a-component)
18
+
*[Cách render component theo điều kiện](/learn/conditional-rendering)
19
+
*[Cách render nhiều component cùng lúc](/learn/rendering-lists)
20
+
*[Cách tránh bug khó hiểu bằng cách giữ component thuần khiết](/learn/keeping-components-pure)
21
+
*[Tại sao hiểu UI của bạn như cây cấu trúc lại hữu ích](/learn/understanding-your-ui-as-a-tree)
22
22
23
23
</YouWillLearn>
24
24
25
-
## Your first component {/*your-first-component*/}
25
+
## Component đầu tiên của bạn {/*your-first-component*/}
26
26
27
-
React applications are built from isolated pieces of UI called *components*. A React component is a JavaScript function that you can sprinkle with markup. Components can be as small as a button, or as large as an entire page. Here is a `Gallery`component rendering three`Profile` components:
27
+
Ứng dụng React được xây dựng từ những phần UI tách biệt gọi là *component*. Một React component là một JavaScript function mà bạn có thể rắc thêm markup. Component có thể nhỏ như một nút bấm, hoặc lớn như toàn bộ trang. Đây là một component `Gallery`render ba component`Profile`:
Read**[Your First Component](/learn/your-first-component)**to learn how to declare and use React components.
61
+
Đọc**[Component Đầu Tiên Của Bạn](/learn/your-first-component)**để học cách khai báo và sử dụng React component.
62
62
63
63
</LearnMore>
64
64
65
-
## Importing and exporting components {/*importing-and-exporting-components*/}
65
+
## Import và export component {/*importing-and-exporting-components*/}
66
66
67
-
You can declare many components in one file, but large files can get difficult to navigate. To solve this, you can *export*a component into its own file, and then *import*that component from another file:
67
+
Bạn có thể khai báo nhiều component trong một file, nhưng file lớn có thể khó điều hướng. Để giải quyết điều này, bạn có thể *export*một component vào file riêng của nó, và sau đó *import* component đó từ file khác:
Read**[Importing and Exporting Components](/learn/importing-and-exporting-components)**to learn how to split components into their own files.
116
+
Đọc**[Import và Export Component](/learn/importing-and-exporting-components)**để học cách tách component vào file riêng của chúng.
117
117
118
118
</LearnMore>
119
119
120
-
## Writing markup with JSX {/*writing-markup-with-jsx*/}
120
+
## Viết markup với JSX {/*writing-markup-with-jsx*/}
121
121
122
-
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information.
122
+
Mỗi React component là một JavaScript function có thể chứa một số markup mà React render vào trình duyệt. React component sử dụng phần mở rộng cú pháp được gọi là JSX để biểu diễn markup đó. JSX trông rất giống HTML, nhưng nó nghiêm ngặt hơn một chút và có thể hiển thị thông tin động.
123
123
124
-
If we paste existing HTML markup into a React component, it won't always work:
124
+
Nếu chúng ta dán markup HTML hiện có vào một React component, nó sẽ không phải lúc nào cũng hoạt động:
125
125
126
126
<Sandpack>
127
127
@@ -150,7 +150,7 @@ img { height: 90px; }
150
150
151
151
</Sandpack>
152
152
153
-
If you have existing HTML like this, you can fix it using a [converter](https://transform.tools/html-to-jsx):
153
+
Nếu bạn có HTML hiện có như thế này, bạn có thể sửa nó bằng cách sử dụng [trình chuyển đổi](https://transform.tools/html-to-jsx):
154
154
155
155
<Sandpack>
156
156
@@ -182,13 +182,13 @@ img { height: 90px; }
182
182
183
183
<LearnMorepath="/learn/writing-markup-with-jsx">
184
184
185
-
Read**[Writing Markup with JSX](/learn/writing-markup-with-jsx)**to learn how to write valid JSX.
185
+
Đọc**[Viết Markup với JSX](/learn/writing-markup-with-jsx)**để học cách viết JSX hợp lệ.
186
186
187
187
</LearnMore>
188
188
189
-
## JavaScript in JSX with curly braces {/*javascript-in-jsx-with-curly-braces*/}
189
+
## JavaScript trong JSX với dấu ngoặc nhọn {/*javascript-in-jsx-with-curly-braces*/}
190
190
191
-
JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to "open a window" to JavaScript:
191
+
JSX cho phép bạn viết markup giống HTML bên trong file JavaScript, giữ logic render và nội dung ở cùng một nơi. Đôi khi bạn sẽ muốn thêm một chút logic JavaScript hoặc tham chiếu đến một thuộc tính động bên trong markup đó. Trong tình huống này, bạn có thể sử dụng dấu ngoặc nhọn trong JSX để "mở cửa sổ" đến JavaScript:
192
192
193
193
<Sandpack>
194
194
@@ -230,13 +230,13 @@ body > div > div { padding: 20px; }
Read **[JavaScript in JSX with Curly Braces](/learn/javascript-in-jsx-with-curly-braces)** to learn how to access JavaScript data from JSX.
233
+
Đọc **[JavaScript trong JSX với Dấu Ngoặc Nhọn](/learn/javascript-in-jsx-with-curly-braces)** để học cách truy cập dữ liệu JavaScript từ JSX.
234
234
235
235
</LearnMore>
236
236
237
-
## Passing props to a component {/*passing-props-to-a-component*/}
237
+
## Truyền props cho component {/*passing-props-to-a-component*/}
238
238
239
-
React components use *props* to communicate with each other. Every parent component can pass some information to its child components by giving them props. Props might remind you of HTML attributes, but you can pass any JavaScript value through them, including objects, arrays, functions, and even JSX!
239
+
React component sử dụng *props* để giao tiếp với nhau. Mọi component cha có thể truyền một số thông tin cho component con của nó bằng cách cung cấp props cho chúng. Props có thể khiến bạn nhớ đến thuộc tính HTML, nhưng bạn có thể truyền bất kỳ giá trị JavaScript nào qua chúng, bao gồm object, array, function và thậm chí cả JSX!
## Render theo điều kiện {/*conditional-rendering*/}
319
319
320
-
Your components will often need to display different things depending on different conditions. In React, you can conditionally render JSX using JavaScript syntax like `if` statements, `&&`, and`? :` operators.
320
+
Component của bạn thường sẽ cần hiển thị những thứ khác nhau tùy thuộc vào các điều kiện khác nhau. Trong React, bạn có thể render JSX theo điều kiện bằng cách sử dụng cú pháp JavaScript như câu lệnh `if`, toán tử `&&` và`? :`.
321
321
322
-
In this example, the JavaScript`&&`operator is used to conditionally render a checkmark:
322
+
Trong ví dụ này, toán tử`&&`JavaScript được sử dụng để render dấu kiểm theo điều kiện:
323
323
324
324
<Sandpack>
325
325
@@ -359,15 +359,15 @@ export default function PackingList() {
359
359
360
360
<LearnMore path="/learn/conditional-rendering">
361
361
362
-
Read **[Conditional Rendering](/learn/conditional-rendering)** to learn the different ways to render content conditionally.
362
+
Đọc **[Render Theo Điều Kiện](/learn/conditional-rendering)** để học các cách khác nhau để render nội dung theo điều kiện.
363
363
364
364
</LearnMore>
365
365
366
-
## Rendering lists {/*rendering-lists*/}
366
+
## Render danh sách {/*rendering-lists*/}
367
367
368
-
You will often want to display multiple similar components from a collection of data. You can use JavaScript's `filter()`and`map()`withReact to filter and transform your array of data into an array of components.
368
+
Bạn sẽ thường muốn hiển thị nhiều component tương tự từ một tập hợp dữ liệu. Bạn có thể sử dụng `filter()` và `map()` của JavaScript với React để lọc và chuyển đổi mảng dữ liệu của bạn thành mảng component.
369
369
370
-
For each array item, you will need to specify a`key`. Usually, you will want to use an IDfrom the database as a `key`. KeysletReact keep track of each item's place in the list even if the list changes.
370
+
Đối với mỗi item trong mảng, bạn sẽ cần chỉ định một `key`. Thông thường, bạn sẽ muốn sử dụng ID từ cơ sở dữ liệu làm `key`. Key cho phép React theo dõi vị trí của từng item trong danh sách ngay cả khi danh sách thay đổi.
371
371
372
372
<Sandpack>
373
373
@@ -459,18 +459,18 @@ h2 { font-size: 20px; }
459
459
460
460
<LearnMorepath="/learn/rendering-lists">
461
461
462
-
Read**[Rendering Lists](/learn/rendering-lists)**to learn how to render a list of components, and how to choose a key.
462
+
Đọc**[Render Danh Sách](/learn/rendering-lists)**để học cách render danh sách component và cách chọn key.
463
463
464
464
</LearnMore>
465
465
466
-
## Keeping components pure {/*keeping-components-pure*/}
Some JavaScript functions are *pure.*A pure function:
468
+
Một số JavaScript function là *thuần khiết.*Một function thuần khiết:
469
469
470
-
***Minds its own business.**It does not change any objects or variables that existed before it was called.
471
-
***Same inputs, same output.**Given the same inputs, a pure function should always return the same result.
470
+
***Chỉ quan tâm đến công việc của mình.**Nó không thay đổi bất kỳ object hoặc biến nào đã tồn tại trước khi nó được gọi.
471
+
***Cùng đầu vào, cùng đầu ra.**Với cùng đầu vào, một function thuần khiết luôn trả về cùng kết quả.
472
472
473
-
By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. Here is an example of an impure component:
473
+
Bằng cách chỉ viết component của bạn như các function thuần khiết một cách nghiêm ngặt, bạn có thể tránh được cả một loại bug khó hiểu và hành vi không thể dự đoán khi codebase của bạn phát triển. Đây là một ví dụ về component không thuần khiết:
474
474
475
475
<Sandpack>
476
476
@@ -496,7 +496,7 @@ export default function TeaSet() {
496
496
497
497
</Sandpack>
498
498
499
-
You can make this component pure by passing a prop instead of modifying a preexisting variable:
499
+
Bạn có thể làm cho component này thuần khiết bằng cách truyền prop thay vì thay đổi biến đã tồn tại trước:
500
500
501
501
<Sandpack>
502
502
@@ -520,43 +520,43 @@ export default function TeaSet() {
520
520
521
521
<LearnMorepath="/learn/keeping-components-pure">
522
522
523
-
Read**[Keeping Components Pure](/learn/keeping-components-pure)**to learn how to write components as pure, predictable functions.
523
+
Đọc**[Giữ Component Thuần Khiết](/learn/keeping-components-pure)**để học cách viết component như những function thuần khiết, có thể dự đoán được.
524
524
525
525
</LearnMore>
526
526
527
-
## Your UI as a tree {/*your-ui-as-a-tree*/}
527
+
## UI của bạn như một cây cấu trúc {/*your-ui-as-a-tree*/}
528
528
529
-
React uses trees to model the relationships between components and modules.
529
+
React sử dụng cây để mô hình hóa các mối quan hệ giữa component và module.
530
530
531
-
A React render tree is a representation of the parent and child relationship between components.
531
+
Một React render tree là sự biểu diễn của mối quan hệ cha và con giữa các component.
532
532
533
533
<Diagramname="generic_render_tree"height={250}width={500}alt="A tree graph with five nodes, with each node representing a component. The root node is located at the top the tree graph and is labelled 'Root Component'. It has two arrows extending down to two nodes labelled 'Component A' and 'Component C'. Each of the arrows is labelled with 'renders'. 'Component A' has a single 'renders' arrow to a node labelled 'Component B'. 'Component C' has a single 'renders' arrow to a node labelled 'Component D'.">
534
534
535
-
An example React render tree.
535
+
Một ví dụ về React render tree.
536
536
537
537
</Diagram>
538
538
539
-
Components near the top of the tree, near the root component, are considered top-level components. Components with no child components are leaf components. This categorization of components is useful for understanding data flow and rendering performance.
539
+
Component gần đỉnh của cây, gần root component, được coi là component cấp cao nhất. Component không có component con là leaf component. Việc phân loại component này hữu ích để hiểu luồng dữ liệu và hiệu suất render.
540
540
541
-
Modelling the relationship between JavaScript modules is another useful way to understand your app. We refer to it as a module dependency tree.
541
+
Mô hình hóa mối quan hệ giữa các JavaScript module là một cách hữu ích khác để hiểu ứng dụng của bạn. Chúng ta gọi nó là module dependency tree.
542
542
543
-
<Diagramname="generic_dependency_tree"height={250}width={500}alt="A tree graph with five nodes. Each node represents a JavaScript module. The top-most node is labelled 'RootModule.js'. It has three arrows extending to the nodes: 'ModuleA.js', 'ModuleB.js', and 'ModuleC.js'. Each arrow is labelled as 'imports'. 'ModuleC.js' node has a single 'imports' arrow that points to a node labelled 'ModuleD.js'.">
543
+
<Diagramname="generic_dependency_tree"height={250}width={500}alt="Một đồ thị cây với năm node. Mỗi node đại diện cho một JavaScript module. Node cao nhất được gắn nhãn 'RootModule.js'. Nó có ba mũi tên kéo dài đến các node: 'ModuleA.js', 'ModuleB.js', và 'ModuleC.js'. Mỗi mũi tên được gắn nhãn 'imports'. Node 'ModuleC.js' có một mũi tên 'imports' duy nhất trỏ đến node được gắn nhãn 'ModuleD.js'.">
544
544
545
-
An example module dependency tree.
545
+
Một ví dụ về module dependency tree.
546
546
547
547
</Diagram>
548
548
549
-
A dependency tree is often used by build tools to bundle all the relevant JavaScript code for the client to download and render. A large bundle size regresses user experience for React apps. Understanding the module dependency tree is helpful to debug such issues.
549
+
Một dependency tree thường được sử dụng bởi các công cụ build để đóng gói tất cả code JavaScript liên quan cho client tải xuống và render. Kích thước bundle lớn làm giảm trải nghiệm người dùng cho ứng dụng React. Hiểu module dependency tree sẽ giúp debug những vấn đề như vậy.
Read**[Your UI as a Tree](/learn/understanding-your-ui-as-a-tree)**to learn how to create a render and module dependency trees for a React app and how they're useful mental models for improving user experience and performance.
553
+
Đọc**[UI Của Bạn Như Một Cây](/learn/understanding-your-ui-as-a-tree)**để học cách tạo render tree và module dependency tree cho ứng dụng React và cách chúng là những mô hình tinh thần hữu ích để cải thiện trải nghiệm người dùng và hiệu suất.
554
554
555
555
</LearnMore>
556
556
557
557
558
-
## What's next? {/*whats-next*/}
558
+
## Tiếp theo là gì? {/*whats-next*/}
559
559
560
-
Head over to [Your First Component](/learn/your-first-component)to start reading this chapter page by page!
560
+
Hãy chuyển đến [Component Đầu Tiên Của Bạn](/learn/your-first-component)để bắt đầu đọc chương này từng trang một!
561
561
562
-
Or, if you're already familiar with these topics, why not read about [Adding Interactivity](/learn/adding-interactivity)?
562
+
Hoặc, nếu bạn đã quen thuộc với những chủ đề này, tại sao không đọc về [Thêm Tương Tác](/learn/adding-interactivity)?
0 commit comments