-
Notifications
You must be signed in to change notification settings - Fork 54
Translate 'Refs Must Have Owner Warning' page #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakubdrozdek
merged 2 commits into
reactjs:master
from
m8ms:warning-refs-must-have-owner
Dec 9, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,45 +4,47 @@ layout: single | |||||
permalink: warnings/refs-must-have-owner.html | ||||||
--- | ||||||
|
||||||
You are probably here because you got one of the following error messages: | ||||||
Jesteś tu najprawdopodobniej z powodu jednego z dwóch błędów: | ||||||
|
||||||
*React 16.0.0+* | ||||||
> Warning: | ||||||
> | ||||||
> 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). | ||||||
|
||||||
*earlier versions of React* | ||||||
*wcześniejsze wersje Reacta* | ||||||
> Warning: | ||||||
> | ||||||
> 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. | ||||||
|
||||||
This usually means one of three things: | ||||||
Zazwyczaj oznacza to jedną z trzech rzeczy: | ||||||
|
||||||
- You are trying to add a `ref` to a function component. | ||||||
- You are trying to add a `ref` to an element that is being created outside of a component's render() function. | ||||||
- You have multiple (conflicting) copies of React loaded (eg. due to a misconfigured npm dependency) | ||||||
- Usiłujesz dodać referencję (`ref`) do komponentu funkcyjnego. | ||||||
- Próbujesz dodać referencję do elementu, który jest tworzony poza metodą `render` komponentu. | ||||||
- Masz załadowanych kilka (konfliktujących) wersji Reacta (np. z powodu źle skonfigurowanych zależności npm). | ||||||
|
||||||
## Refs on Function Components {#refs-on-function-components} | ||||||
## Referencje do komponentów funkcyjnych {#refs-on-function-components} | ||||||
|
||||||
If `<Foo>` is a function component, you can't add a ref to it: | ||||||
Jeśli `<Foo>` jest komponentem funkcyjnym, nie możesz tworzyć do niego referencji: | ||||||
|
||||||
```js | ||||||
// Doesn't work if Foo is a function! | ||||||
// nie zadziała, jeśli Foo jest funkcją! | ||||||
<Foo ref={foo} /> | ||||||
``` | ||||||
|
||||||
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). | ||||||
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). | ||||||
|
||||||
## Strings Refs Outside the Render Method {#strings-refs-outside-the-render-method} | ||||||
## Referencje tekstowe poza metodą render {#strings-refs-outside-the-render-method} | ||||||
|
||||||
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: | ||||||
Oznacza to najczęściej, że próbujesz dodać referencję do komponentu, który nie ma "właściciela" | ||||||
(czyli nie został stworzony wewnątrz metody `render` innego komponentu). Na przykład to nie zadziała: | ||||||
|
||||||
```js | ||||||
// Doesn't work! | ||||||
// Nie działa! | ||||||
ReactDOM.render(<App ref="app" />, el); | ||||||
``` | ||||||
|
||||||
Try rendering this component inside of a new top-level component which will hold the ref. Alternatively, you may use a callback ref: | ||||||
Spróbuj wyrenderować komponent wewnątrz jakiegoś komponentu-rodzica, który będzie przechowywać referencję. | ||||||
Możesz też użyć funkcji zwrotnej (ang. *callback*): | ||||||
|
||||||
```js | ||||||
let app; | ||||||
|
@@ -54,10 +56,13 @@ ReactDOM.render( | |||||
); | ||||||
``` | ||||||
|
||||||
Consider if you [really need a ref](/docs/refs-and-the-dom.html#when-to-use-refs) before using this approach. | ||||||
Zanim zdecydujesz się na takie rozwiązanie, upewnij się, [czy na pewno potrzebujesz referencji](/docs/refs-and-the-dom.html#when-to-use-refs). | ||||||
|
||||||
## Multiple copies of React {#multiple-copies-of-react} | ||||||
## Wiele kopii Reacta {#multiple-copies-of-react} | ||||||
|
||||||
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. | ||||||
Bower dobrze radzi sobie z usuwaniem zduplikowanych zależności, ale npm już nie. | ||||||
Jeśli nie robisz nic (szczególnego) z referencjami, jest spora szansa, że problem nie leży postronie Twoich referencji, | ||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. j/w |
||||||
Może to powodować problemy. | ||||||
|
||||||
If you are using npm... `npm ls` or `npm ls react` might help illuminate. | ||||||
Jeśli używasz npm... `npm ls` albo `npm ls react` mogą rzucić trochę światła na problem. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W dokumentacji zaimki piszemy małymi literami.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To jest dyskusyjne: https://sjp.pwn.pl/poradnia/haslo/Twoj-czy-twoj;2426.html
O ile nigdzie nie piszemy z wielkiej, to luz.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dokładnie - nigdzie nie piszemy wielką literą, stąd moja uwaga :-)