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: content/warnings/refs-must-have-owner.md
+23-18Lines changed: 23 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,47 @@ layout: single
4
4
permalink: warnings/refs-must-have-owner.html
5
5
---
6
6
7
-
You are probably here because you got one of the following error messages:
7
+
Jesteś tu najprawdopodobniej z powodu jednego z dwóch błędów:
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
+
*wcześniejsze wersje Reacta*
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
+
Zazwyczaj oznacza to jedną z trzech rzeczy:
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)
21
+
-Usiłujesz dodać referencję (`ref`) do komponentu funkcyjnego.
22
+
-Próbujesz dodać referencję do elementu, który jest tworzony poza metodą `render` komponentu.
23
+
-Masz załadowanych kilka (konfliktujących) wersji Reacta (np. z powodu źle skonfigurowanych zależności npm).
24
24
25
-
## Refs on Function Components {#refs-on-function-components}
25
+
## Referencje do komponentów funkcyjnych {#refs-on-function-components}
26
26
27
-
If`<Foo>`is a function component, you can't add a ref to it:
27
+
Jeśli`<Foo>`jest komponentem funkcyjnym, nie możesz tworzyć do niego referencji:
28
28
29
29
```js
30
-
//Doesn't work if Foo is a function!
30
+
//nie zadziała, jeśli Foo jest funkcją!
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
+
Jeśli musisz dodać referencję do komponentu, zamień go najpierw na klasę lub rozważ, [czy na pewno potrzebujesz referencji](/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
+
## Referencje tekstowe poza metodą 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
+
Oznacza to najczęściej, że próbujesz dodać referencję do komponentu, który nie ma "właściciela"
39
+
(czyli nie został stworzony wewnątrz metody `render` innego komponentu). Na przykład to nie zadziała:
39
40
40
41
```js
41
-
//Doesn't work!
42
+
//Nie działa!
42
43
ReactDOM.render(<App ref="app"/>, el);
43
44
```
44
45
45
-
Try rendering this component inside of a new top-level component which will hold the ref. Alternatively, you may use a callback ref:
46
+
Spróbuj wyrenderować komponent wewnątrz jakiegoś komponentu-rodzica, który będzie przechowywać referencję.
47
+
Możesz też użyć funkcji zwrotnej (ang. *callback*):
46
48
47
49
```js
48
50
let app;
@@ -54,10 +56,13 @@ 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
+
Zanim zdecydujesz się na takie rozwiązanie, upewnij się, [czy na pewno potrzebujesz referencji](/docs/refs-and-the-dom.html#when-to-use-refs).
58
60
59
-
## Multiple copies of React {#multiple-copies-of-react}
61
+
## Wiele kopii Reacta {#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 dobrze radzi sobie z usuwaniem zduplikowanych zależności, ale npm już nie.
64
+
Jeśli nie robisz nic (szczególnego) z referencjami, jest spora szansa, że problem nie leży postronie Twoich referencji,
65
+
a raczej w tym, że w Twoim projekcie znalazła się więcej niż jedna instancja Reacta. Czasem zaciągając zewnętrzny moduł z npm otrzymasz dodatkową kopię Reacta w bibliotece zależności.
66
+
Może to powodować problemy.
62
67
63
-
If you are using npm... `npm ls`or`npm ls react`might help illuminate.
68
+
Jeśli używasz npm... `npm ls`albo`npm ls react`mogą rzucić trochę światła na problem.
0 commit comments