Skip to content

Commit 4897b26

Browse files
authored
Merge pull request #38 from tuantvk/master
Translate FAQ/Function and FAQ/Styling
2 parents b1f7799 + 00cd756 commit 4897b26

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

content/docs/faq-build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: faq-build
3-
title: Babel, JSX, và từng bước xây dựng
3+
title: Babel, JSX, và các bước xây dựng
44
permalink: docs/faq-build.html
55
layout: docs
66
category: FAQ

content/docs/faq-functions.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
22
id: faq-functions
3-
title: Passing Functions to Components
3+
title: Truyền Functions cho Component
44
permalink: docs/faq-functions.html
55
layout: docs
66
category: FAQ
77
---
88

9-
### How do I pass an event handler (like onClick) to a component? {#how-do-i-pass-an-event-handler-like-onclick-to-a-component}
9+
### Làm thế nào tôi truyền một sự kiện (như onClick) cho một component?{#how-do-i-pass-an-event-handler-like-onclick-to-a-component}
1010

11-
Pass event handlers and other functions as props to child components:
11+
Truyền một sự kiện xử lý và một function khác như là một props cho component con:
1212

1313
```jsx
1414
<button onClick={this.handleClick}>
1515
```
1616

17-
If you need to have access to the parent component in the handler, you also need to bind the function to the component instance (see below).
17+
Nếu bạn cần truy cập vào component cha trong xử lý, bạn cần phải bind function cụ thể với một component (xem bên dưới).
1818

19-
### How do I bind a function to a component instance? {#how-do-i-bind-a-function-to-a-component-instance}
19+
### Làm sao tôi bind một function cho component cụ thể? {#how-do-i-bind-a-function-to-a-component-instance}
2020

21-
There are several ways to make sure functions have access to component attributes like `this.props` and `this.state`, depending on which syntax and build steps you are using.
21+
Có một số cách để đảm bảo các function có quyền truy cập vào các thuộc tính component như `this.props` `this.state`, tùy thuộc vào cú pháp và các bước xây dựng mà bạn đang sử dụng.
2222

23-
#### Bind in Constructor (ES2015) {#bind-in-constructor-es2015}
23+
#### Bind trong Constructor (ES2015) {#bind-in-constructor-es2015}
2424

2525
```jsx
2626
class Foo extends Component {
@@ -51,7 +51,7 @@ class Foo extends Component {
5151
}
5252
```
5353

54-
#### Bind in Render {#bind-in-render}
54+
#### Bind trong Render {#bind-in-render}
5555

5656
```jsx
5757
class Foo extends Component {
@@ -64,11 +64,11 @@ class Foo extends Component {
6464
}
6565
```
6666

67-
>**Note:**
67+
>**Lưu ý:**
6868
>
69-
>Using `Function.prototype.bind` in render creates a new function each time the component renders, which may have performance implications (see below).
69+
>Sử dụng `Function.prototype.bind` trong hàm render tạo ra một function mới mỗi lần component renders, điều đó có thể liên quan tới hiệu suất (Xem bên dưới).
7070
71-
#### Arrow Function in Render {#arrow-function-in-render}
71+
#### Arrow Function trong Render {#arrow-function-in-render}
7272

7373
```jsx
7474
class Foo extends Component {
@@ -81,19 +81,19 @@ class Foo extends Component {
8181
}
8282
```
8383

84-
>**Note:**
84+
>**Lưu ý:**
8585
>
86-
>Using an arrow function in render creates a new function each time the component renders, which may break optimizations based on strict identity comparison.
86+
>Sử dụng arrow function trong hàm render tạo ra một function mới mỗi lần component renders, điều đó làm phá vỡ tính tối ưu dựa trên so sánh các định danh.
8787
88-
### Is it OK to use arrow functions in render methods? {#is-it-ok-to-use-arrow-functions-in-render-methods}
88+
### Có được sử dụng arrow function trong hàm render không? {#is-it-ok-to-use-arrow-functions-in-render-methods}
8989

90-
Generally speaking, yes, it is OK, and it is often the easiest way to pass parameters to callback functions.
90+
Nói chung, đồng ý, nó OK, và nó thường là cách dễ nhất để truyền tham số cho các callback functions.
9191

92-
If you do have performance issues, by all means, optimize!
92+
Nếu bạn có vấn đề về hiệu suất, bằng mọi cách, hãy tối ưu hóa!
9393

94-
### Why is binding necessary at all? {#why-is-binding-necessary-at-all}
94+
### Tại sao ràng buộc cần thiết ở tất cả? {#why-is-binding-necessary-at-all}
9595

96-
In JavaScript, these two code snippets are **not** equivalent:
96+
Trong JavaScript, hai đoạn code này **không** tương đương:
9797

9898
```js
9999
obj.method();
@@ -104,15 +104,15 @@ var method = obj.method;
104104
method();
105105
```
106106

107-
Binding methods helps ensure that the second snippet works the same way as the first one.
107+
Các phương thức binding giúp đảm bảo rằng đoạn code thứ hai hoạt động giống như cách đầu tiên.
108108

109-
With React, typically you only need to bind the methods you *pass* to other components. For example, `<button onClick={this.handleClick}>` passes `this.handleClick` so you want to bind it. However, it is unnecessary to bind the `render` method or the lifecycle methods: we don't pass them to other components.
109+
Với React, thông thường bạn chỉ cần bind các phương thức bạn *truyền* cho các component khác. Ví dụ: `<button onClick = {this.handleClick}>` truyền `this.handleClick` vì vậy bạn phải bind nó. Tuy nhiên, không cần thiết phải bind hàm `render` hoặc phương thức vòng đời: chúng tôi không truyền chúng cho các component khác.
110110

111-
[This post by Yehuda Katz](https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/) explains what binding is, and how functions work in JavaScript, in detail.
111+
[Bài đăng này của Yehuda Katz](https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/) giải thích binding là gì và cách các function hoạt động trong JavaScript, một cách chi tiết.
112112

113-
### Why is my function being called every time the component renders? {#why-is-my-function-being-called-every-time-the-component-renders}
113+
### Tại sao function của tôi lại gọi lại mỗi khi component render? {#why-is-my-function-being-called-every-time-the-component-renders}
114114

115-
Make sure you aren't _calling the function_ when you pass it to the component:
115+
Hãy chắc chắn rằng bạn đã _call function_ khi bạn truyền nó cho component:
116116

117117
```jsx
118118
render() {
@@ -121,7 +121,7 @@ render() {
121121
}
122122
```
123123

124-
Instead, *pass the function itself* (without parens):
124+
Thay thế, *pass the function itself* (without parens):
125125

126126
```jsx
127127
render() {
@@ -130,9 +130,9 @@ render() {
130130
}
131131
```
132132

133-
### How do I pass a parameter to an event handler or callback? {#how-do-i-pass-a-parameter-to-an-event-handler-or-callback}
133+
### Làm cách nào để truyền tham số cho xử lý sự kiện hoặc callback? {#how-do-i-pass-a-parameter-to-an-event-handler-or-callback}
134134

135-
You can use an arrow function to wrap around an event handler and pass parameters:
135+
Bạn có thể sử dụng arrow function để bọc xung quanh xử lý sự kiện và truyền tham số:
136136

137137
```jsx
138138
<button onClick={() => this.handleClick(id)} />
@@ -144,7 +144,7 @@ This is equivalent to calling `.bind`:
144144
<button onClick={this.handleClick.bind(this, id)} />
145145
```
146146

147-
#### Example: Passing params using arrow functions {#example-passing-params-using-arrow-functions}
147+
#### Ví dụ: Truyền tham số sử dụng arrow function {#example-passing-params-using-arrow-functions}
148148

149149
```jsx
150150
const A = 65 // ASCII character code
@@ -178,9 +178,9 @@ class Alphabet extends React.Component {
178178
}
179179
```
180180

181-
#### Example: Passing params using data-attributes {#example-passing-params-using-data-attributes}
181+
#### Ví dụ: Truyền tham số sử dụng data-attributes {#example-passing-params-using-data-attributes}
182182

183-
Alternately, you can use DOM APIs to store data needed for event handlers. Consider this approach if you need to optimize a large number of elements or have a render tree that relies on React.PureComponent equality checks.
183+
Thông thường, bạn có thể sử dụng DOM APIs để lưu trữ dữ liệu cần thiết cho xử lý sự kiện. Hãy xem xét phương pháp này nếu bạn cần tối ưu hóa một số lượng lớn các phần tử hoặc có một render tree dựa trên các phương thức kiểm tra sự bằng nhau React.PureComponent.
184184

185185
```jsx
186186
const A = 65 // ASCII character code
@@ -218,23 +218,23 @@ class Alphabet extends React.Component {
218218
}
219219
```
220220

221-
### How can I prevent a function from being called too quickly or too many times in a row? {#how-can-i-prevent-a-function-from-being-called-too-quickly-or-too-many-times-in-a-row}
221+
### Làm thế nào tôi có thể ngăn chặn một function được gọi quá nhanh hoặc quá nhiều lần liên tiếp? {#how-can-i-prevent-a-function-from-being-called-too-quickly-or-too-many-times-in-a-row}
222222

223-
If you have an event handler such as `onClick` or `onScroll` and want to prevent the callback from being fired too quickly, then you can limit the rate at which callback is executed. This can be done by using:
223+
Nếu bạn có một sự kiện như `onClick` hoặc `onScroll` và muốn ngăn hàm callback gọi lại quá nhanh, thì bạn có thể giới hạn tốc độ thực hiện hàm callback. Điều này có thể được thực hiện bằng cách sử dụng:
224224

225-
- **throttling**: sample changes based on a time based frequency (eg [`_.throttle`](https://lodash.com/docs#throttle))
226-
- **debouncing**: publish changes after a period of inactivity (eg [`_.debounce`](https://lodash.com/docs#debounce))
227-
- **`requestAnimationFrame` throttling**: sample changes based on [`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) (eg [`raf-schd`](https://github.com/alexreardon/raf-schd))
225+
- **throttling**: thay đổi dựa vào tần suất dựa trên thời gian (eg [`_.throttle`](https://lodash.com/docs#throttle))
226+
- **debouncing**: thực hiện dựa vào những thay đổi sau một khoảng thời gian (eg [`_.debounce`](https://lodash.com/docs#debounce))
227+
- **`requestAnimationFrame` throttling**: thay đổi mẫu dựa trên [`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) (eg [`raf-schd`](https://github.com/alexreardon/raf-schd))
228228

229-
See [this visualization](http://demo.nimius.net/debounce_throttle/) for a comparison of `throttle` and `debounce` functions.
229+
Xem [mô phỏng này](http://demo.nimius.net/debounce_throttle/) để so sánh giữa các hàm `throttle` `debounce`.
230230

231-
> Note:
231+
> Lưu ý:
232232
>
233-
> `_.debounce`, `_.throttle` and `raf-schd` provide a `cancel` method to cancel delayed callbacks. You should either call this method from `componentWillUnmount` _or_ check to ensure that the component is still mounted within the delayed function.
233+
> `_.debounce`, `_.throttle` `raf-schd` cung cấp một phương thức `cancel` để huỷ các hàm callback đang bị trì hoãn. Bạn nên gọi phương thức này từ `componentWillUnmount` _hoặc_ kiểm tra để đảm bảo rằng component đó vẫn được gắn trong function bị trì hoãn.
234234
235235
#### Throttle {#throttle}
236236

237-
Throttling prevents a function from being called more than once in a given window of time. The example below throttles a "click" handler to prevent calling it more than once per second.
237+
Throttle ngăn chặn một function được gọi nhiều lần trong một khung thời gian nhất định. Ví dụ dưới đây điều chỉnh một sự kiện xử lý "click" để ngăn chặn việc gọi nó nhiều hơn một lần mỗi giây.
238238

239239
```jsx
240240
import throttle from 'lodash.throttle';
@@ -262,7 +262,7 @@ class LoadMoreButton extends React.Component {
262262

263263
#### Debounce {#debounce}
264264

265-
Debouncing ensures that a function will not be executed until after a certain amount of time has passed since it was last called. This can be useful when you have to perform some expensive calculation in response to an event that might dispatch rapidly (eg scroll or keyboard events). The example below debounces text input with a 250ms delay.
265+
Debounce đảm bảo rằng một hàm sẽ không được thực thi sau một khoảng thời gian nhất định kể từ khi nó được gọi lần cuối. Điều này có thể hữu ích khi bạn phải thực hiện một số tính toán phức tạp để đáp ứng với một sự kiện có thể gửi đi nhanh chóng (ví dụ: các sự kiện scroll hoặc bàn phím). Ví dụ dưới đây nhập văn bản với độ trễ 250ms.
266266

267267
```jsx
268268
import debounce from 'lodash.debounce';
@@ -304,11 +304,11 @@ class Searchbox extends React.Component {
304304

305305
#### `requestAnimationFrame` throttling {#requestanimationframe-throttling}
306306

307-
[`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) is a way of queuing a function to be executed in the browser at the optimal time for rendering performance. A function that is queued with `requestAnimationFrame` will fire in the next frame. The browser will work hard to ensure that there are 60 frames per second (60 fps). However, if the browser is unable to it will naturally *limit* the amount of frames in a second. For example, a device might only be able to handle 30 fps and so you will only get 30 frames in that second. Using `requestAnimationFrame` for throttling is a useful technique in that it prevents you from doing more than 60 updates in a second. If you are doing 100 updates in a second this creates additional work for the browser that the user will not see anyway.
307+
[`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) à cách sắp xếp thứ tự thực thi của một hàm trên trình duyệt tại thời điểm tối ưu cho hiệu suất hiển thị. Một hàm được xếp trong `requestAnimationFrame` sẽ kích hoạt trong khung tiếp theo. Trình duyệt sẽ làm việc liên tục để đảm bảo có 60 khung hình mỗi giây (60 fps). Tuy nhiên, nếu trình duyệt không thể, nó sẽ tự nhiên *giới hạn* số lượng khung hình trong một giây. Ví dụ: một thiết bị có thể chỉ có thể xử lý 30 fps và do đó bạn sẽ chỉ nhận được 30 khung hình trong giây đó. Sử dụng `requestAnimationFrame` để điều chỉnh là một kỹ thuật hữu ích ở chỗ nó ngăn bạn thực hiện hơn 60 cập nhật trong một giây. Nếu bạn đang thực hiện 100 bản cập nhật trong một giây, nó sẽ tạo ra thêm việc cho trình duyệt mà người dùng không hề nhìn thấy.
308308

309-
>**Note:**
309+
>**Lưu ý:**
310310
>
311-
>Using this technique will only capture the last published value in a frame. You can see an example of how this optimization works on [`MDN`](https://developer.mozilla.org/en-US/docs/Web/Events/scroll)
311+
>Sử dụng kĩ thuật này sẽ xem được giá trị cuối cùng của mỗi khung hình. Bạn có thể xem một ví dụ về cách tối ưu hóa này hoạt động trên [`MDN`](https://developer.mozilla.org/en-US/docs/Web/Events/scroll)
312312
313313
```jsx
314314
import rafSchedule from 'raf-schd';
@@ -349,6 +349,6 @@ class ScrollListener extends React.Component {
349349
}
350350
```
351351

352-
#### Testing your rate limiting {#testing-your-rate-limiting}
352+
#### Kiểm tra tỉ lệ giới hạn {#testing-your-rate-limiting}
353353

354-
When testing your rate limiting code works correctly it is helpful to have the ability to fast forward time. If you are using [`jest`](https://facebook.github.io/jest/) then you can use [`mock timers`](https://facebook.github.io/jest/docs/en/timer-mocks.html) to fast forward time. If you are using `requestAnimationFrame` throttling then you may find [`raf-stub`](https://github.com/alexreardon/raf-stub) to be a useful tool to control the ticking of animation frames.
354+
Khi kiểm tra code của bạn hoạt động có đang chính xác, thật hữu ích để có khả năng chuyển nhanh thời gian. Nếu bạn đang sử dụng [`jest`](https://facebook.github.io/jest/) thì bạn có thể sử dụng [`mock timers`](https://facebook.github.io/jest/docs/en/timer-mocks.html) để chuyển nhanh thời gian. Nếu bạn đang sử dụng `requestAnimationFrame` thì bạn có thể thấy [`raf-stub`](https://github.com/alexreardon/raf-stub) là một công cụ hữu ích để kiểm soát việc đánh dấu các khung hình động.

content/docs/faq-styling.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ layout: docs
66
category: FAQ
77
---
88

9-
### Làm thế nào tôi chèn class CSS cho components? {#how-do-i-add-css-classes-to-components}
9+
### Làm thế nào tôi chèn class CSS cho các component? {#how-do-i-add-css-classes-to-components}
1010

1111
Truyền tên của class cho prop là `className`:
1212

@@ -16,7 +16,7 @@ render() {
1616
}
1717
```
1818

19-
It is common for CSS classes to depend on the component props or state:
19+
Thông thường các class CSS phụ thuộc vào các component props hoặc state:
2020

2121
```jsx
2222
render() {
@@ -30,21 +30,21 @@ render() {
3030

3131
>Tip
3232
>
33-
>If you often find yourself writing code like this, [classnames](https://www.npmjs.com/package/classnames#usage-with-reactjs) package can simplify it.
33+
>Nếu bạn thường thấy mình viết code như thế , [classnames](https://www.npmjs.com/package/classnames#usage-with-reactjs) thư viện này sẽ làm đơn giản nó.
3434
3535
### Tôi có dùng được inline styles? {#can-i-use-inline-styles}
3636

3737
Có, xem tài liệu styling tại [đây](/docs/dom-elements.html#style).
3838

3939
### Viết inline styles xấu? {#are-inline-styles-bad}
4040

41-
Các class CSS thường sẽ có hiệu xuất tốt hơn là inline styles.
41+
Các class CSS thường sẽ có hiệu suất tốt hơn là inline styles.
4242

4343
### CSS-in-JS là gì? {#what-is-css-in-js}
4444

45-
"CSS-in-JS" refers to a pattern where CSS is composed using JavaScript instead of defined in external files. Read a comparison of CSS-in-JS libraries [here](https://github.com/MicheleBertoli/css-in-js).
45+
"CSS-in-JS" đề cập đến một pattern trong đó CSS ​​được tạo bằng JavaScript thay vì được định nghĩa trong các tệp bên ngoài. Đọc một bài viết so sánh các thư viện CSS-in-JS [ở đây](https://github.com/MicheleBertoli/css-in-js).
4646

47-
_Note that this functionality is not a part of React, but provided by third-party libraries._ React does not have an opinion about how styles are defined; if in doubt, a good starting point is to define your styles in a separate `*.css` file as usual and refer to them using [`className`](/docs/dom-elements.html#classname).
47+
_Lưu ý đây không phải là thư viện của React, nhưng được cung câp bởi thư viện thứ ba._ React không có ý kiến về cách xác định style; nếu nghi ngờ, bạn có thể định nghĩa style trong một tệp `*.css` riêng và tham chiếu tới chúng sử dụng [`className`](/docs/dom-elements.html#classname).
4848

4949
### Tôi có thể dùng animations trong React? {#can-i-do-animations-in-react}
5050

content/docs/nav.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@
138138
- id: faq-ajax
139139
title: AJAX và APIs
140140
- id: faq-build
141-
title: Babel, JSX, and Build Steps
141+
title: Babel, JSX, và các bước xây dựng
142142
- id: faq-functions
143-
title: Passing Functions to Components
143+
title: Truyền Functions cho Component
144144
- id: faq-state
145145
title: Component State
146146
- id: faq-styling

0 commit comments

Comments
 (0)