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
You are probably here because you got one of the following error messages:
7
+
Вероятно, вы зашли на эту страницу потому, что получили одно из следующих сообщений об ошибке:
8
8
9
9
*React 16.0.0+*
10
10
> Warning:
11
11
>
12
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).
13
13
14
-
*earlier versions of React*
14
+
*более ранние версии React*
15
15
> Warning:
16
16
>
17
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.
18
18
19
-
This usually means one of three things:
19
+
Обычно это означает одну из трёх вещей:
20
20
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)
-Вы пытаетесь добавить `ref`к элементу, который был создан вне метода `render()` текущего компонента.
23
+
-У вас загружено несколько конфликтующих копий React (например из-за неправильной настройки npm зависимостей).
24
24
25
-
## Refs on Function Components {#refs-on-function-components}
25
+
## Рефы в функциональных компонентах {#refs-on-function-components}
26
26
27
-
If`<Foo>`is a function component, you can't add a ref to it:
27
+
Если`<Foo>`задан функциональным компонентом, то вы не можете на нем добавить `ref`:
28
28
29
29
```js
30
-
//Doesn't work if Foo is a function!
30
+
//Не работает, если Foo это фукнция!
31
31
<Foo ref={foo} />
32
32
```
33
33
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
+
Если нужно добавить `ref` к компоненту, сначала преобразуйте его в класс, или не пользуйтесь механизмом рефов, потому что он нужен [достаточно редко](/docs/refs-and-the-dom.html#when-to-use-refs).
35
35
36
-
## Strings Refs Outside the Render Method {#strings-refs-outside-the-render-method}
36
+
## Строковые рефы вне метода `render` {#strings-refs-outside-the-render-method}
37
37
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
+
Обычно это означает, что вы пытаетесь добавить реф к компонентy, который не имеет владельца (т.е. не был создан внутри метода `render` какого-либо компонента).
39
+
40
+
Следующий пример работать не будет:
39
41
40
42
```js
41
-
//Doesn't work!
43
+
//Не работает!
42
44
ReactDOM.render(<App ref="app"/>, el);
43
45
```
44
46
45
-
Try rendering this component inside of a new top-level component which will hold the ref. Alternatively, you may use a callback ref:
47
+
Попробуйте отрендерить этот компонент внутри нового компонента-обертки, который будет содержать реф. Как вариант - вы можете использовать колбэк-реф:
46
48
47
49
```js
48
50
let app;
@@ -54,10 +56,10 @@ ReactDOM.render(
54
56
);
55
57
```
56
58
57
-
Consider if you [really need a ref](/docs/refs-and-the-dom.html#when-to-use-refs)before using this approach.
59
+
Хорошо подумайте -- [правда ли вам нужен реф](/docs/refs-and-the-dom.html#when-to-use-refs)перед использованием этого подхода.
58
60
59
-
## Multiple copies of React {#multiple-copies-of-react}
61
+
## Несколько копий React {#multiple-copies-of-react}
60
62
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.
63
+
Bower хорошо решает вопрос дублирования зависимостей, а вот npm нет. Если вы не делаете с вашими рефами ничего специфичного, есть большая вероятность, что проблема не в вашем коде, а в том, что в вашем проекте загружено несколько копий React. Иногда, когда вы устанавливаете сторонний пакет через npm, вы можете получить дублирование библиотеки из зависимостей и это может создать проблему.
62
64
63
-
If you are using npm...`npm ls`or`npm ls react`might help illuminate.
65
+
Если вы используете npm...`npm ls`или`npm ls react`может помочь разобраться.
0 commit comments