Skip to content

Commit d7df40b

Browse files
translate warnings/refs-must-have-owner.md
1 parent 81947c4 commit d7df40b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

content/warnings/refs-must-have-owner.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ layout: single
44
permalink: warnings/refs-must-have-owner.html
55
---
66

7-
You are probably here because you got one of the following error messages:
7+
Có thể bạn đang ở đây vì bạn đang gặp một trong các thông báo lỗi sau đây:
88

99
*React 16.0.0+*
10-
> Warning:
10+
> Lời cảnh báo:
1111
>
12-
> Element ref was specified as a string (myRefName) but no owner was set. You may have multiple copies of React loaded. (details: https://fb.me/react-refs-must-have-owner).
12+
> Element ref đã được chỉ định dưới dạng một string (myRefName) nhưng không có chủ sở hữu được thiết lập. Bạn có thể đang nạp nhiều bản sao của React. (thông tin chi tiết: https://fb.me/react-refs-must-have-owner).
1313
14-
*earlier versions of React*
15-
> Warning:
14+
*đối với các phiên bản trước của React*
15+
> Lời cảnh báo:
1616
>
17-
> addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded.
17+
> addComponentAsRefTo(...): Chỉ duy nhất ReactOwner mới có thể có refs. Bạn có thể đang thêm một ref vào một component không được tạo ra bên trong phương thức `render` của component này, hoặc bạn có nhiều bản sao của React đang được nạp.
1818
19-
This usually means one of three things:
19+
Điều này thường được hiểu theo một trong ba điều sau:
2020

21-
- You are trying to add a `ref` to a function component.
22-
- You are trying to add a `ref` to an element that is being created outside of a component's render() function.
23-
- You have multiple (conflicting) copies of React loaded (eg. due to a misconfigured npm dependency)
21+
- Bạn đang cố gắng thêm một `ref` vào một function component.
22+
- Bạn đang cố gắng thêm một `ref` vào một element đang được khởi tạo bên ngoài hàm render của component bạn đang muốn thêm `ref`.
23+
- Bạn có nhiều (conflicting: xung đột) bản sao của React đang được nạp (ví dụ : do npm dependency bị cấu hình sai)
2424

25-
## Refs on Function Components {#refs-on-function-components}
25+
## Refs trong Function Components {#refs-on-function-components}
2626

27-
If `<Foo>` is a function component, you can't add a ref to it:
27+
Nếu `<Foo>` là một function component, Bạn không thể thêm một ref vào nó:
2828

2929
```js
30-
// Doesn't work if Foo is a function!
30+
// Không hoạt động nếu Foo là một function!
3131
<Foo ref={foo} />
3232
```
3333

34-
If you need to add a ref to a component, convert it to a class first, or consider not using refs as they are [rarely necessary](/docs/refs-and-the-dom.html#when-to-use-refs).
34+
Nếu bạn cần thêm một ref vào component, hãy chuyển component đó sang class thay vì dùng function, hoặc xem xét không sử dụng refs vì chúng [hiếm khi cần thiết](/docs/refs-and-the-dom.html#when-to-use-refs).
3535

36-
## Strings Refs Outside the Render Method {#strings-refs-outside-the-render-method}
36+
## Strings Refs bên ngoài phương thức Render {#strings-refs-outside-the-render-method}
3737

38-
This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component's `render` method). For example, this won't work:
38+
Điều này thường có nghĩa là bạn đang cố gắng thêm một ref vào component không có chủ sở hữu (nghĩa là nó không được tạo bên trong phương thức `render` của component khác). Ví dụ, điều này sẽ không thể hoạt động:
3939

4040
```js
41-
// Doesn't work!
41+
// Không hoạt động!
4242
ReactDOM.render(<App ref="app" />, el);
4343
```
4444

45-
Try rendering this component inside of a new top-level component which will hold the ref. Alternatively, you may use a callback ref:
45+
Thử rendering component này bên trong một component cấp cao hơn (thường được gọi là component cha), component này sẽ giữ ref. Ngoài ra, bạn có thể sử dụng một callback ref như sau:
4646

4747
```js
4848
let app;
@@ -54,10 +54,10 @@ ReactDOM.render(
5454
);
5555
```
5656

57-
Consider if you [really need a ref](/docs/refs-and-the-dom.html#when-to-use-refs) before using this approach.
57+
Hãy cân nhắc xem bạn có [thực sự cần một ref](/docs/refs-and-the-dom.html#when-to-use-refs) trước khi sử dụng phương pháp này hay không.
5858

59-
## Multiple copies of React {#multiple-copies-of-react}
59+
## Các bản sao của React {#multiple-copies-of-react}
6060

61-
Bower does a good job of deduplicating dependencies, but npm does not. If you aren't doing anything (fancy) with refs, there is a good chance that the problem is not with your refs, but rather an issue with having multiple copies of React loaded into your project. Sometimes, when you pull in a third-party module via npm, you will get a duplicate copy of the dependency library, and this can create problems.
61+
Bower thực hiện tốt công việc loại bỏ trùng lặp các dependency, nhưng npm thì không. Nếu bạn không làm bất cứ điều gì (yêu thích) với refs, đây là một cơ hội tốt vì vấn đề không phải ở refs của bạn, mà là vấn đề với việc đang có nhiều bản sao của React được nạp vào dự án của bạn. Đôi khi, khi bạn đang tải về một module thứ ba thông qua npm, bạn sẽ nhận được một bản sao của thư viện dependency, và điều này có thể đã tạo ra vấn đề.
6262

63-
If you are using npm... `npm ls` or `npm ls react` might help illuminate.
63+
Nếu bạn đang sử dụng npm... `npm ls` hoặc `npm ls react` có thể giúp bạn giải quyết.

0 commit comments

Comments
 (0)