-
Notifications
You must be signed in to change notification settings - Fork 54
Translate Components and Props
page
#45
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 41 commits into
reactjs:master
from
arekmaz:translate-components-and-props
Mar 18, 2019
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5f3b610
Translate introduction and `Function and Class Components` section
arekmaz 08b79bd
Translate the title
arekmaz 0fcf228
Translate `Rendering a Component` and `Composing Components` sections
arekmaz abaa91a
Translate `Extracting Components` section
arekmaz cd78f7c
Translate `Props are Read-Only` section
arekmaz 06d755e
Small translation details changes
arekmaz 879859f
Change MDN docs link to polish version
arekmaz e198ef6
Update content/docs/components-and-props.md
jakubdrozdek 8300056
Update content/docs/components-and-props.md
jakubdrozdek 7f9b37a
Update content/docs/components-and-props.md
jakubdrozdek ee5862c
Update content/docs/components-and-props.md
jakubdrozdek fcce1bc
Update content/docs/components-and-props.md
jakubdrozdek 2d35d16
Update content/docs/components-and-props.md
jakubdrozdek 939d755
Update content/docs/components-and-props.md
jakubdrozdek 37154df
Update content/docs/components-and-props.md
jakubdrozdek 279d6b8
Update content/docs/components-and-props.md
jakubdrozdek b6badbd
Update content/docs/components-and-props.md
jakubdrozdek 30f6423
Update content/docs/components-and-props.md
jakubdrozdek 281ad73
Update content/docs/components-and-props.md
jakubdrozdek 922378f
Update content/docs/components-and-props.md
jakubdrozdek 10db43f
Update content/docs/components-and-props.md
jakubdrozdek 309ec5a
Update content/docs/components-and-props.md
jakubdrozdek a626d5a
Update content/docs/components-and-props.md
jakubdrozdek 234aafb
Update content/docs/components-and-props.md
jakubdrozdek cccc7d1
Update content/docs/components-and-props.md
jakubdrozdek 9e489eb
Update content/docs/components-and-props.md
jakubdrozdek 1300296
Update content/docs/components-and-props.md
jakubdrozdek 17d16a9
Update content/docs/components-and-props.md
jakubdrozdek 1a2998b
Update content/docs/components-and-props.md
jakubdrozdek 8bc0be5
Update content/docs/components-and-props.md
jakubdrozdek 753cc66
Update content/docs/components-and-props.md
jakubdrozdek e65dedd
Update content/docs/components-and-props.md
jakubdrozdek 45b354b
Update content/docs/components-and-props.md
jakubdrozdek 0040e76
Update content/docs/components-and-props.md
jakubdrozdek f7fa854
Update content/docs/components-and-props.md
jakubdrozdek 5e8bdbd
Update content/docs/components-and-props.md
jakubdrozdek c76cf15
Update content/docs/components-and-props.md
jakubdrozdek 36a975f
Add small suggested translation changes
arekmaz 0a69b1e
Update content/docs/components-and-props.md
jfrej fb3393a
Update content/docs/components-and-props.md
jfrej 163f195
Update content/docs/components-and-props.md
jfrej 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
id: components-and-props | ||
title: Components and Props | ||
title: Komponenty i właściwości | ||
permalink: docs/components-and-props.html | ||
redirect_from: | ||
- "docs/reusable-components.html" | ||
|
@@ -16,57 +16,57 @@ prev: rendering-elements.html | |
next: state-and-lifecycle.html | ||
--- | ||
|
||
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to the idea of components. You can find a [detailed component API reference here](/docs/react-component.html). | ||
Komponenty pozwalają podzielić interfejs użytkownika na niezależne, pozwalające na ponowne użycie części i myśleć o każdej z nich osobno. Ta strona wprowadza do pojęcia komponentów. W osobnym rozdziale opisaliśmy [szczegółową dokumentację API komponentów](/docs/react-component.html). | ||
|
||
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen. | ||
Koncepcyjnie, komponenty są jak javascriptowe funkcje. Przyjmują one arbitralne wartości na wejściu (nazywane "właściwościami" (ang. *props*)) i zwracają reactowe elementy opisujące, co powinno się pojawić na ekranie. | ||
|
||
## Function and Class Components {#function-and-class-components} | ||
## Komponenty funkcyjne i klasowe {#function-and-class-components} | ||
|
||
The simplest way to define a component is to write a JavaScript function: | ||
Najprostszym sposobem na zdefiniowanie komponentu jest napisanie javascriptowej funkcji: | ||
|
||
```js | ||
function Welcome(props) { | ||
return <h1>Hello, {props.name}</h1>; | ||
return <h1>Cześć, {props.name}</h1>; | ||
} | ||
``` | ||
|
||
This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "function components" because they are literally JavaScript functions. | ||
Ta funkcja jest poprawnym reactowym komponentem, ponieważ przyjmuje pojedynczy argument "props" (który oznacza "właściwości", z ang. *properties*), będący obiektem z danymi, i zwraca reactowy element. Takie komponenty nazywamy "komponentami funkcyjnymi", gdyż są one dosłownie javascriptowymi funkcjami. | ||
|
||
You can also use an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) to define a component: | ||
Do zdefiniowania komponentu możesz również użyć [klasy ze standardu ES6](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Classes): | ||
|
||
```js | ||
class Welcome extends React.Component { | ||
render() { | ||
return <h1>Hello, {this.props.name}</h1>; | ||
return <h1>Cześć, {this.props.name}</h1>; | ||
} | ||
} | ||
``` | ||
|
||
The above two components are equivalent from React's point of view. | ||
Obydwa powyższe komponenty są równoważne z punktu widzenia Reacta. | ||
|
||
Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness. | ||
Klasy mają kilka dodatkowych cech, które omówimy w [kolejnych rozdziałach](/docs/state-and-lifecycle.html). Do tego czasu będziemy używać komponentów funkcyjnych ze względu na ich zwięzły zapis. | ||
|
||
## Rendering a Component {#rendering-a-component} | ||
## Renderowanie komponentu {#rendering-a-component} | ||
|
||
Previously, we only encountered React elements that represent DOM tags: | ||
Poprzednio napotykaliśmy reactowe elementy, które reprezentowały znaczniki DOM: | ||
|
||
```js | ||
const element = <div />; | ||
``` | ||
|
||
However, elements can also represent user-defined components: | ||
Elementy mogą również reprezentować komponenty zdefiniowane przez użytkownika: | ||
|
||
```js | ||
const element = <Welcome name="Sara" />; | ||
``` | ||
|
||
When React sees an element representing a user-defined component, it passes JSX attributes to this component as a single object. We call this object "props". | ||
Kiedy React widzi element reprezentujący komponent zdefiniowany przez użytkownika, przekazuje do niego JSX-owe atrybuty jako jeden obiekt. Obiekt ten nazywamy "właściwościami" komponentu. | ||
|
||
For example, this code renders "Hello, Sara" on the page: | ||
Dla przykładu, poniższy kod renderuje na stronie napis "Cześć, Sara": | ||
|
||
```js{1,5} | ||
function Welcome(props) { | ||
return <h1>Hello, {props.name}</h1>; | ||
return <h1>Cześć, {props.name}</h1>; | ||
} | ||
|
||
const element = <Welcome name="Sara" />; | ||
|
@@ -78,28 +78,28 @@ ReactDOM.render( | |
|
||
[](codepen://components-and-props/rendering-a-component) | ||
|
||
Let's recap what happens in this example: | ||
Podsumujmy, co dzieje się w tym przykładzie: | ||
|
||
1. We call `ReactDOM.render()` with the `<Welcome name="Sara" />` element. | ||
2. React calls the `Welcome` component with `{name: 'Sara'}` as the props. | ||
3. Our `Welcome` component returns a `<h1>Hello, Sara</h1>` element as the result. | ||
4. React DOM efficiently updates the DOM to match `<h1>Hello, Sara</h1>`. | ||
1. Wywołujemy `ReactDOM.render()` z elementem `<Welcome name="Sara" />`. | ||
2. React wywołuje komponent `Welcome` z właściwościami `{name: 'Sara'}`. | ||
3. Nasz komponent `Welcome` jako wynik zwraca element `<h1>Cześć, Sara</h1>`. | ||
4. React DOM w optymalny sposób aktualizuje drzewo DOM, aby odpowiadało elementowi `<h1>Cześć, Sara</h1>`. | ||
|
||
>**Note:** Always start component names with a capital letter. | ||
>**Wskazówka:** Zawsze zaczynaj nazwy komponentów od dużej litery. | ||
> | ||
>React treats components starting with lowercase letters as DOM tags. For example, `<div />` represents an HTML div tag, but `<Welcome />` represents a component and requires `Welcome` to be in scope. | ||
>React traktuje komponenty zaczynające się od małej litery jako tagi drzewa DOM. Na przykład, `<div />` reprezentuje HTML-owy znacznik 'div', ale już `<Welcome />` reprezentuje komponent i wymaga, aby `Welcome` było w zasięgu (ang. *scope*). | ||
> | ||
>To learn more about the reasoning behind this convention, please read [JSX In Depth](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized). | ||
>Aby dowiedzieć się więcej o uzasadnieniu tej konwencji, przeczytaj [dogłębną analizę składni JSX](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized). | ||
|
||
## Composing Components {#composing-components} | ||
## Kompozycja komponentów {#composing-components} | ||
|
||
Components can refer to other components in their output. This lets us use the same component abstraction for any level of detail. A button, a form, a dialog, a screen: in React apps, all those are commonly expressed as components. | ||
Komponenty przy zwracaniu wyniku mogą mogą odwoływać się do innych komponentów. Pozwala to używać tej samej abstrakcji komponentu na dowolnym poziomie szczegółowości. Przycisk, formularz, okno dialogowe, ekran - w aplikacjach reactowych tego typu składniki są zwykle reprezentowane przez dedykowane komponenty. | ||
|
||
For example, we can create an `App` component that renders `Welcome` many times: | ||
Możemy dla przykładu stworzyć komponent `App`, który wielokrotnie renderuje komponent `Welcome`: | ||
|
||
```js{8-10} | ||
function Welcome(props) { | ||
return <h1>Hello, {props.name}</h1>; | ||
return <h1>Cześć, {props.name}</h1>; | ||
} | ||
|
||
function App() { | ||
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. Proponuję przystosować imiona do polskich realiów. Sara, Karol, Edyta? :) 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. Z tego co widzę wszędzie jest Sara, ale może coś przeoczyłem |
||
|
@@ -120,13 +120,13 @@ ReactDOM.render( | |
|
||
[](codepen://components-and-props/composing-components) | ||
|
||
Typically, new React apps have a single `App` component at the very top. However, if you integrate React into an existing app, you might start bottom-up with a small component like `Button` and gradually work your way to the top of the view hierarchy. | ||
Nowe aplikacje reactowe na samej górze drzewa zazwyczaj renderują pojedynczy komponent `App`. Jeśli jednak musisz zintegrować Reacta z istniejącą aplikacją, możesz zacząć od samego dołu, dodając niewielkie komponenty (np. `Button`) i stopniowo przepisywać całą strukturę aż do samej góry. | ||
|
||
## Extracting Components {#extracting-components} | ||
## Wyciąganie komponentów {#extracting-components} | ||
|
||
Don't be afraid to split components into smaller components. | ||
Nie bój się dzielenia komponentów na mniejsze części. | ||
|
||
For example, consider this `Comment` component: | ||
Rozważ poniższy komponent `Comment`: | ||
|
||
```js | ||
function Comment(props) { | ||
|
@@ -154,11 +154,11 @@ function Comment(props) { | |
|
||
[](codepen://components-and-props/extracting-components) | ||
|
||
It accepts `author` (an object), `text` (a string), and `date` (a date) as props, and describes a comment on a social media website. | ||
Przyjmuje on obiekt `author`, napis `text` i datę `date` jako właściwości i zwraca strukturę opisującą komentarz na portalu mediów społecznościowych. | ||
|
||
This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it. | ||
Zmiana tego komponentu czy ponowne użycie jego poszczególnych części może okazać się skomplikowane z powodu całego tego zagnieżdżenia. Rozbijmy go zatem na kilka mniejszych komponentów. | ||
|
||
First, we will extract `Avatar`: | ||
Najpierw wydzielmy komponent `Avatar`: | ||
|
||
```js{3-6} | ||
function Avatar(props) { | ||
|
@@ -171,11 +171,11 @@ function Avatar(props) { | |
} | ||
``` | ||
|
||
The `Avatar` doesn't need to know that it is being rendered inside a `Comment`. This is why we have given its prop a more generic name: `user` rather than `author`. | ||
`Avatar` nie musi wiedzieć, że jest renderowany wewnątrz komponentu `Comment`. Dlatego też daliśmy jego właściwości bardziej ogólną nazwę `user` zamiast `author`. | ||
|
||
We recommend naming props from the component's own point of view rather than the context in which it is being used. | ||
Zalecamy nadawanie nazw właściwościom z punktu widzenia komponentu, a nie kontekstu, w którym jest używany. | ||
|
||
We can now simplify `Comment` a tiny bit: | ||
Możemy teraz uprościć nieco komponent `Comment`: | ||
|
||
```js{5} | ||
function Comment(props) { | ||
|
@@ -198,7 +198,7 @@ function Comment(props) { | |
} | ||
``` | ||
|
||
Next, we will extract a `UserInfo` component that renders an `Avatar` next to the user's name: | ||
Następnie wydzielmy komponent `UserInfo`, który wyrenderuje `Avatar` obok nazwy użytkownika: | ||
|
||
```js{3-8} | ||
function UserInfo(props) { | ||
|
@@ -213,7 +213,7 @@ function UserInfo(props) { | |
} | ||
``` | ||
|
||
This lets us simplify `Comment` even further: | ||
To pozwala nam uprościć `Comment` jeszcze bardziej: | ||
|
||
```js{4} | ||
function Comment(props) { | ||
|
@@ -233,30 +233,30 @@ function Comment(props) { | |
|
||
[](codepen://components-and-props/extracting-components-continued) | ||
|
||
Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (`Button`, `Panel`, `Avatar`), or is complex enough on its own (`App`, `FeedStory`, `Comment`), it is a good candidate to be a reusable component. | ||
Wyciąganie komponentów może z początku wydawać się żmudnym zajęciem, ale posiadanie palety pozwalających na ponowne użycie komponentów jest opłacalne w większych aplikacjach. Dobrą praktyczną zasadą jest, że jeśli część twojego interfejsu użytkownika jest używana wielokrotnie (np. `Button`, `Panel`, `Avatar`) lub jest ona dostatecznie skomplikowana sama w sobie (np. `App`, `FeedStory`, `Comment`), jest ona dobrym kandydatem do stania się komponentem wielokrotnego użytku. | ||
|
||
## Props are Read-Only {#props-are-read-only} | ||
## Właściwości są tylko do odczytu {#props-are-read-only} | ||
|
||
Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum` function: | ||
Bez względu na to, czy zadeklarujesz komponent [jako funkcję czy klasę](#function-and-class-components), nie może on nigdy modyfikować swoich właściwości. Rozważ następującą funkcję `sum`: | ||
|
||
```js | ||
function sum(a, b) { | ||
return a + b; | ||
} | ||
``` | ||
|
||
Such functions are called ["pure"](https://en.wikipedia.org/wiki/Pure_function) because they do not attempt to change their inputs, and always return the same result for the same inputs. | ||
Funkcje tego typu nazywane są ["czystymi"](https://en.wikipedia.org/wiki/Pure_function) (ang. *pure function*), dlatego że nie próbują one zmieniać swoich argumentów i zawsze zwracają ten sam wynik dla tych samych argumentów. | ||
|
||
In contrast, this function is impure because it changes its own input: | ||
W przeciwieństwie do poprzedniej funkcji, ta poniżej nie jest "czysta", ponieważ zmienia swój argument. | ||
|
||
```js | ||
function withdraw(account, amount) { | ||
account.total -= amount; | ||
} | ||
``` | ||
|
||
React is pretty flexible but it has a single strict rule: | ||
React jest bardzo elastyczny, ale ma jedną ścisłą zasadę: | ||
|
||
**All React components must act like pure functions with respect to their props.** | ||
**Wszytkie komponenty muszą zachowywać się jak czyste funkcje w odniesieniu do ich właściwości.** | ||
|
||
Of course, application UIs are dynamic and change over time. In the [next section](/docs/state-and-lifecycle.html), we will introduce a new concept of "state". State allows React components to change their output over time in response to user actions, network responses, and anything else, without violating this rule. | ||
Rzecz jasna, interfejsy użytkownika w aplikacjach są zwykle dynamiczne, zmieniają się w czasie. W [kolejnym rozdziale](/docs/state-and-lifecycle.html) wprowadzimy nowe pojęcie "stanu". Stan pozwala komponentom reactowym na zmianę swojego wyniku w czasie, w odpowiedzi na akcje użytkownika, żądania sieciowe itp. bez naruszania powyższej zasady. |
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.
To ewentualnie zmieniłbym na
Uwaga
, tak jak np. tu: https://github.com/reactjs/pl.reactjs.org/pull/40/files#diff-6024d880e5eef39cfbff54653ef34fb6R61Wskazówka
nie jest właściwie niepoprawna, ale bardziej pasuje do angielskiegoTip
.