Skip to content

Commit 1dd5374

Browse files
Adding translation of conditional-rendering
1 parent 6ae18e4 commit 1dd5374

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

content/docs/conditional-rendering.md

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
22
id: conditional-rendering
3-
title: Conditional Rendering
3+
title: Renderowanie warunkowe
44
permalink: docs/conditional-rendering.html
55
prev: handling-events.html
66
next: lists-and-keys.html
77
redirect_from:
88
- "tips/false-in-jsx.html"
99
---
1010

11-
In React, you can create distinct components that encapsulate behavior you need. Then, you can render only some of them, depending on the state of your application.
11+
React umożliwia tworzenie odrębnych komponentów, które hermetyzują (ang. *encapsulate*) pożądane przez ciebie metody. Następnie zrenderowane mogą być wybrane komponenty, w zależności od stanu twojej aplikacji.
1212

13-
Conditional rendering in React works the same way conditions work in JavaScript. Use JavaScript operators like [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) or the [conditional operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) to create elements representing the current state, and let React update the UI to match them.
13+
Renderowanie warunkowe działa w Reakcie tak samo jak warunki JavaScriptowe. Aby stworzyć elementy odzwierciedlające aktualny stan aplikacji, należy użyć operatora takiego jak [if](https://developer.mozilla.org/pl/docs/Learn/Getting_started_with_the_web/JavaScript_basics#Warunki) lub [operatora warunkowego](https://developer.mozilla.org/pl/docs/Web/JavaScript/Referencje/Operatory/Operator_warunkowy) oraz pozwolić Reactowi je dopasować poprzez aktualizację interfejsu użytkownika.
1414

15-
Consider these two components:
15+
Rozważmy następujące dwa komponenty:
1616

1717
```js
1818
function UserGreeting(props) {
19-
return <h1>Welcome back!</h1>;
19+
return <h1>Witamy ponownie!</h1>;
2020
}
2121

2222
function GuestGreeting(props) {
23-
return <h1>Please sign up.</h1>;
23+
return <h1>Proszę się zapisać.</h1>;
2424
}
2525
```
2626

27-
We'll create a `Greeting` component that displays either of these components depending on whether a user is logged in:
27+
Stworzymy komponent `Greeting` (ang. *Powitanie*), który wyświetlał będzie jeden lub drugi z powyższych komponentów w zależności od tego czy użytkownik jest zalogowany.
2828

2929
```javascript{3-7,11,12}
3030
function Greeting(props) {
@@ -42,37 +42,38 @@ ReactDOM.render(
4242
);
4343
```
4444

45-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
45+
[**Przetestuj kod na CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
4646

47-
This example renders a different greeting depending on the value of `isLoggedIn` prop.
47+
Powitanie renderowane przez kod w powyższym przykładzie zależy of wartości właściwości `isLoggedIn`.
4848

49-
### Element Variables {#element-variables}
49+
### Zmienne elementowe {#element-variables}
5050

51-
You can use variables to store elements. This can help you conditionally render a part of the component while the rest of the output doesn't change.
51+
Elementy mogą być przechowywane w zmiennych. Pozwala to na warunkowe renderowanie określonej części, komponentu podczas gdy pozostałe dane wyjściowe nie ulegają zmianie.
5252

53-
Consider these two new components representing Logout and Login buttons:
53+
Przyjrzyjmy się dwóm nowym komponentom tworzącym przyciski logowania Zaloguj się (ang. *Login*) oraz Wyloguj się (ang. *Logout*):
5454

5555
```js
5656
function LoginButton(props) {
5757
return (
5858
<button onClick={props.onClick}>
59-
Login
59+
Zaloguj się
6060
</button>
6161
);
6262
}
6363

6464
function LogoutButton(props) {
6565
return (
6666
<button onClick={props.onClick}>
67-
Logout
67+
Wyloguj się
6868
</button>
6969
);
7070
}
7171
```
7272

73-
In the example below, we will create a [stateful component](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) called `LoginControl`.
73+
W przykładzie poniżej zbudujemy [komponent ze stanem](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) o nazwie `LoginControl` (pol. *kontrola logowania*)
74+
75+
W zależności od aktualnego stanu będzie on renderował przycisk logowania (`<LoginButton />`) lub wylogowania `<LogoutButton />` . Będzie on również renderował komponent `<Greeting />` z poprzedniego przykładu:
7476

75-
It will render either `<LoginButton />` or `<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
7677

7778
```javascript{20-25,29,30}
7879
class LoginControl extends React.Component {
@@ -116,23 +117,24 @@ ReactDOM.render(
116117
);
117118
```
118119

119-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
120+
[**Przetestuj kod na CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
121+
122+
Deklarowanie zmiennej oraz stosowanie warunku `if` to dobry sposób na warunkowe renderowanie komponentu. Czasem jednak przydaje się nieco krótsza składnia. JSX umożliwia kilka różnych opcji warunków wewnątrz liniowych. Przedstawiamy je poniżej.
120123

121-
While declaring a variable and using an `if` statement is a fine way to conditionally render a component, sometimes you might want to use a shorter syntax. There are a few ways to inline conditions in JSX, explained below.
122124

123-
### Inline If with Logical && Operator {#inline-if-with-logical--operator}
125+
### Wewnątrz liniowy warunek `if` z użyciem logicznego operatora `&&` {#inline-if-with-logical--operator}
124126

125-
You may [embed any expressions in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) by wrapping them in curly braces. This includes the JavaScript logical `&&` operator. It can be handy for conditionally including an element:
127+
JSX umożliwia stosowanie w nawiasach klamrowych [wszelkich wyrażeń](/docs/introducing-jsx.html#embedding-expressions-in-jsx), łącznie z JavaScriptowym operatorem logicznym `&&`. Jest to przydatne do warunkowego załączania elementu.
126128

127129
```js{6-10}
128130
function Mailbox(props) {
129131
const unreadMessages = props.unreadMessages;
130132
return (
131133
<div>
132-
<h1>Hello!</h1>
134+
<h1>Cześć!</h1>
133135
{unreadMessages.length > 0 &&
134136
<h2>
135-
You have {unreadMessages.length} unread messages.
137+
Masz {unreadMessages.length} nieprzeczytanych wiadomości.
136138
</h2>
137139
}
138140
</div>
@@ -146,30 +148,30 @@ ReactDOM.render(
146148
);
147149
```
148150

149-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
151+
[**Przetestuj kod na CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
150152

151-
It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.
153+
Powyższy kod działa ponieważ w JavaScripcie `true && wyrażenie` zawsze jest ewaluowane jako `wyrażenie`, natomiast `false && wyrażenie` jako `false`.
152154

153-
Therefore, if the condition is `true`, the element right after `&&` will appear in the output. If it is `false`, React will ignore and skip it.
155+
Zatem jeśli warunek jest `true`, element następujący bezpośrednio po `&&` zostanie ukazany w danych wyjściowych. Natomiast jeśli warunek jest `fałszywy`, React zignoruje go i pominie przy renderowaniu.
154156

155-
### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
157+
### Warunek if-else z operatorem warunkowym {#inline-if-else-with-conditional-operator}
156158

157-
Another method for conditionally rendering elements inline is to use the JavaScript conditional operator [`condition ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
159+
Kolejną metodą renderowania warunkowego wewnątrz liniowego jest stosowanie JavaScriptowego operatora warunkowego [`warunek ? true : false`](https://developer.mozilla.org/pl/docs/Web/JavaScript/Referencje/Operatory/Operator_warunkowy).
158160

159-
In the example below, we use it to conditionally render a small block of text.
161+
W przykładzie poniżej używamy go, aby warunkowo zrenderować mały blok tekstu.
160162

161163
```javascript{5}
162164
render() {
163165
const isLoggedIn = this.state.isLoggedIn;
164166
return (
165167
<div>
166-
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in.
168+
Użytkownik jest teraz <b>{isLoggedIn ? 'zalogowany' : 'niezalogowany'}</b>.
167169
</div>
168170
);
169171
}
170172
```
171173

172-
It can also be used for larger expressions although it is less obvious what's going on:
174+
Rozwiązanie to może być stosowane również w przypadku dłuższych wyrażeń:
173175

174176
```js{5,7,9}
175177
render() {
@@ -185,14 +187,16 @@ render() {
185187
);
186188
}
187189
```
190+
Czytelność takich wyrażeń jest oczywiście nieco mniejsza. Podobnie jak w JavaScripcie, wybór odpowiedniego stylu zależy od preferencji twoich i twojego zespołu. Jednocześnie należy pamiętać, że kiedy warunki stają się nazbyt złożone, dobrze jest roważyć możliwość [stworzenia osobnego komponentu](/docs/components-and-props.html#extracting-components)
191+
192+
193+
### Zapobieganie renderowaniu komponentu {#preventing-component-from-rendering}
188194

189-
Just like in JavaScript, it is up to you to choose an appropriate style based on what you and your team consider more readable. Also remember that whenever conditions become too complex, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
195+
W sporadycznych przypadkach, może zachodzić potrzeba ukrycia się komponentu mimo, iż został on zrenderowany przez inny komponent. Aby to umożliwić należy zastosować wartość `null` zamiast jego renderowanych danych wyjściowych.
190196

191-
### Preventing Component from Rendering {#preventing-component-from-rendering}
192197

193-
In rare cases you might want a component to hide itself even though it was rendered by another component. To do this return `null` instead of its render output.
198+
W przykładzie poniżej, renderowanie baneru ostrzegawczego `<WarningBanner />` jest uzależnione od wartości właściwości o nazwie `warn` (ang. *ostrzeż*). Jeśli wartość tej właściwości jest `false`, wówczas komponent ten nie jest renderowany.
194199

195-
In the example below, the `<WarningBanner />` is rendered depending on the value of the prop called `warn`. If the value of the prop is `false`, then the component does not render:
196200

197201
```javascript{2-4,29}
198202
function WarningBanner(props) {
@@ -202,7 +206,7 @@ function WarningBanner(props) {
202206
203207
return (
204208
<div className="warning">
205-
Warning!
209+
Ostrzeżenie!
206210
</div>
207211
);
208212
}
@@ -225,7 +229,7 @@ class Page extends React.Component {
225229
<div>
226230
<WarningBanner warn={this.state.showWarning} />
227231
<button onClick={this.handleToggleClick}>
228-
{this.state.showWarning ? 'Hide' : 'Show'}
232+
{this.state.showWarning ? 'Ukryj' : 'Pokaż'}
229233
</button>
230234
</div>
231235
);
@@ -238,6 +242,6 @@ ReactDOM.render(
238242
);
239243
```
240244

241-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
245+
[**Przetestuj kod na CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
242246

243-
Returning `null` from a component's `render` method does not affect the firing of the component's lifecycle methods. For instance `componentDidUpdate` will still be called.
247+
Zwrócenie wartości `null` z metody `render` danego komponentu nie ma wpływu na wywoływanie metod cyklu życia tego komponentu. To znaczy, że np. metoda `componentDidUpdate` w dalszym ciągu zostanie wywołana.

0 commit comments

Comments
 (0)