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
It accepts`author` (an object), `text` (a string), and`date` (a date) as props, and describes a comment on a social media website.
157
+
Nó nhận`author` (một object), `text` (một sâu kí tự), và`date` (ngày tháng) làm props, và mô phỏng lại một bình luận trên mạng xã hội.
158
158
159
-
This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it.
159
+
Component này có thể khó để thay đổi vì cấu trúc lồng nhau, đồng thời cũng khó có thể tái sử dụng lại các thành phần con bên trong nó. Hãy thử chia một vài components từ nó.
160
160
161
-
First, we will extract`Avatar`:
161
+
Đầu tiên, chúng ta sẽ chia`Avatar`:
162
162
163
163
```js{3-6}
164
164
function Avatar(props) {
@@ -171,11 +171,11 @@ function Avatar(props) {
171
171
}
172
172
```
173
173
174
-
The `Avatar`doesn't need to know that it is being rendered inside a `Comment`. This is why we have given its prop a more generic name: `user`rather than`author`.
174
+
`Avatar`không cần phải biết nó đang được render bên trong `Comment`. Đây là lí do tại sao chúng ta truyền vào nó một prop với cái tên tổng quát là: `user`thay vì`author`.
175
175
176
-
We recommend naming props from the component's own point of view rather than the context in which it is being used.
176
+
Chúng tôi khuyến khích việc đặt tên cho props dựa trên góc nhìn từ chính component hơn là ngữ cảnh mà component được sử dụng.
177
177
178
-
We can now simplify `Comment`a tiny bit:
178
+
Chúng ta có thể đơn giản hoá `Comment`đi một chút:
179
179
180
180
```js{5}
181
181
function Comment(props) {
@@ -198,7 +198,7 @@ function Comment(props) {
198
198
}
199
199
```
200
200
201
-
Next, we will extract a `UserInfo` component that renders an`Avatar`next to the user's name:
201
+
Tiếp theo, chúng ta sẽ chia component `UserInfo`, component này sẽ render`Avatar`bên cạnh tên của user:
202
202
203
203
```js{3-8}
204
204
function UserInfo(props) {
@@ -213,7 +213,7 @@ function UserInfo(props) {
213
213
}
214
214
```
215
215
216
-
This lets us simplify `Comment`even further:
216
+
Điều này giúp chúng ta có thể đơn giản hoá `Comment`hơn nữa:
Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (`Button`, `Panel`, `Avatar`), or is complex enough on its own (`App`, `FeedStory`, `Comment`), it is a good candidate to be extracted to a separate component.
236
+
Chia các components ngay từ đầu là một công việc không đơn giản, nhưng bù lại chúng ta sẽ có được một tập hợp các components có thể tái sử dụng trong các ứng dụng lớn hơn khác. Một nguyên tắc quan trọng đó là nếu một phần UI của bạn được sử dụng lại nhiều lần (`Button`, `Panel`, `Avatar`), hoặc đủ phức tạp (`App`, `FeedStory`, `Comment`), thì đó là thời điểm thích hợp để chia chúng thành các component riêng.
237
237
238
-
## Props are Read-Only {#props-are-read-only}
238
+
## Props chỉ dùng để đọc {#props-are-read-only}
239
239
240
-
Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum`function:
240
+
Khi bạn định nghĩa một component [dưới dạng function hoặc class](#function-and-class-components), thì nó không được phép thay đổi props của chính nó. Hãy cùng phân tích hàm `sum`dưới đây:
0 commit comments