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/docs/conditional-rendering.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
1
---
2
2
id: conditional-rendering
3
-
title: Conditional Rendering
3
+
title: Feltételes renderelés
4
4
permalink: docs/conditional-rendering.html
5
5
prev: handling-events.html
6
6
next: lists-and-keys.html
7
7
redirect_from:
8
8
- "tips/false-in-jsx.html"
9
9
---
10
10
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
+
A React-ben olyan különböző komponenseket készíthetsz, amik különféle viselkedéseket tudnak elkülöníteni, magukba foglalni. Ezután tudsz kimondottan csak néhányat renderelni, az alkalmazás állapotától függően.
12
12
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
+
A feltételes renderelés React-ben ugyanúgy működik mint ahogy a feltételek működnek JavaScript-ben. Használj JavaScript operátorokat mint az [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)vagy a [feltételes operátor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)elemek készítéséhez, amik reprezentálják a jelenlegi állapotot, és hagyd hogy a React ennek megfelelően frissítse a felhasználói felületet.
14
14
15
-
Consider these two components:
15
+
Vedd ezt a két komponenst:
16
16
17
17
```js
18
18
functionUserGreeting(props) {
19
-
return<h1>Welcome back!</h1>;
19
+
return<h1>Üdv újra!</h1>;
20
20
}
21
21
22
22
functionGuestGreeting(props) {
23
-
return<h1>Please sign up.</h1>;
23
+
return<h1>Kérjük, regisztrálj.</h1>;
24
24
}
25
25
```
26
26
27
-
We'll create a`Greeting`component that displays either of these components depending on whether a user is logged in:
27
+
Készíteni fogunk egy`Greeting`komponenst, ami ezen komponensek egyikét fogja megjeleníteni attól függően, hogy a felhasználó be van-e jelentkezve:
28
28
29
29
```javascript{3-7,11,12}
30
30
function Greeting(props) {
@@ -42,37 +42,37 @@ ReactDOM.render(
42
42
);
43
43
```
44
44
45
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
45
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
46
46
47
-
This example renders a different greeting depending on the value of `isLoggedIn` prop.
47
+
Ez a példa különféle üdvözléseket renderel az `isLoggenIn` prop értékétől függően.
48
48
49
-
### Element Variables {#element-variables}
49
+
### Elem változók {#element-variables}
50
50
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
+
Használhatsz változókat elemek tárolására. Ez segít feltételesen renderelni a komponens egy részét, amíg a kimenet többi része nem változik.
52
52
53
-
Consider these two new components representing Logout and Login buttons:
53
+
Vedd ezt a két komponenst amik Kijelentkezés és Bejelentkezés gombokat képviselnek:
54
54
55
55
```js
56
56
functionLoginButton(props) {
57
57
return (
58
58
<button onClick={props.onClick}>
59
-
Login
59
+
Bejelentkezés
60
60
</button>
61
61
);
62
62
}
63
63
64
64
functionLogoutButton(props) {
65
65
return (
66
66
<button onClick={props.onClick}>
67
-
Logout
67
+
Kijelentkezés
68
68
</button>
69
69
);
70
70
}
71
71
```
72
72
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
+
Az alábbi példában készíteni fogunk egy `LoginControl` nevű [állapot-teljes komponenst](/docs/state-and-lifecycle.html#adding-local-state-to-a-class).
74
74
75
-
It will render either `<LoginButton />` or `<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
75
+
Ez vagy a `<LoginButton />`-t vagy pedig a `<LogoutButton />`-t fogja renderelni a jelenlegi állapotától függően. Valamint renderelni fogja a`<Greeting />`-et is az előző példából:
76
76
77
77
```javascript{20-25,29,30}
78
78
class LoginControl extends React.Component {
@@ -116,23 +116,23 @@ ReactDOM.render(
116
116
);
117
117
```
118
118
119
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
119
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
120
120
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.
121
+
Változók deklarálása és `if`utasítások használata teljesen rendben van egy komponens feltételes renderelése esetén, néha azonban talán szívesen használnál egy rövidebb szintaxist. Az alábbiakban elmagyarázzuk, hogy van néhány módja helyben kifejtett feltételeknek JSX-ben.
122
122
123
-
### Inline If with Logical && Operator {#inline-if-with-logical--operator}
123
+
### Helyben kifejtett if logikai && operátorral {#inline-if-with-logical--operator}
124
124
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:
125
+
Kapcsos zárójelekkel bármilyen [kifejezést JSX-be tudsz ágyazni](/docs/introducing-jsx.html#embedding-expressions-in-jsx). Ez magába foglalja a logikai`&&`operátort is. Hasznos lehet ha egy elemet feltételesen szeretnénk mutatni:
126
126
127
127
```js{6-10}
128
128
function Mailbox(props) {
129
129
const unreadMessages = props.unreadMessages;
130
130
return (
131
131
<div>
132
-
<h1>Hello!</h1>
132
+
<h1>Helló!</h1>
133
133
{unreadMessages.length > 0 &&
134
134
<h2>
135
-
You have {unreadMessages.length} unread messages.
135
+
{unreadMessages.length} olvasatlan üzeneted van.
136
136
</h2>
137
137
}
138
138
</div>
@@ -146,30 +146,30 @@ ReactDOM.render(
146
146
);
147
147
```
148
148
149
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
149
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
150
150
151
-
It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.
151
+
Ez azért működik JavaScript-ben, mert a `true && kifejezés` mindig a `kifejezés`-re értékelődik ki, valamint a `false && kifejezés` pedig mindig `false`-ra.
152
152
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.
153
+
Ezért ha a feltétel `true`, az elem ami `&&`operátor jobb oldalán van, meg fog jelenni a kimenetben. Ha a feltétel`false` a React figyelmen kívül hagyja az elemet.
154
154
155
-
### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
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).
157
+
A helyben kifejtett feltételes renderelés egy másik módja lehet a JavaScript feltételes operátor[`feltétel ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
158
158
159
-
In the example below, we use it to conditionally render a small block of text.
159
+
Az alábbi példában ezt használjuk egy kis szövegrészlet feltételes renderelésére.
160
160
161
161
```javascript{5}
162
162
render() {
163
163
const isLoggedIn = this.state.isLoggedIn;
164
164
return (
165
165
<div>
166
-
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in.
166
+
A felhasználó <b>{isLoggedIn ? 'jelenleg be van ' : 'nincs be'}</b>jelentkezve.
167
167
</div>
168
168
);
169
169
}
170
170
```
171
171
172
-
It can also be used for larger expressions although it is less obvious what's going on:
172
+
Használható nagyobb kifejezésekhez is, bár így kevésbé nyilvánvaló mi is történik éppen:
173
173
174
174
```js{5,7,9}
175
175
render() {
@@ -186,13 +186,13 @@ render() {
186
186
}
187
187
```
188
188
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).
189
+
Ugyanúgy ahogy JavaScript-ben, te döntöd el hogy melyik stílust választod attól függően hogy te és a csapatod mit találnak olvashatóbbnak. Valamint emlékezz, ha a feltételek túl összetetté kezdenek válni, talán itt az ideje [kivonni egy komponenst](/docs/components-and-props.html#extracting-components).
190
190
191
-
### Preventing Component from Rendering {#preventing-component-from-rendering}
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.
193
+
Ritka esetekben szeretnéd ha a komponensed elrejtené magát akkor is, ha az más komponensek által renderelve lett. Ehhez egyszerűen adj vissza`null`-t a renderelés kimenetében.
194
194
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:
195
+
Az alábbi példában a `<WarningBanner />`a `warn` prop értékétől függően van renderelve. Ha a prop értéke`false`, a komponens nem lesz renderelve:
196
196
197
197
```javascript{2-4,29}
198
198
function WarningBanner(props) {
@@ -202,7 +202,7 @@ function WarningBanner(props) {
202
202
203
203
return (
204
204
<div className="warning">
205
-
Warning!
205
+
Figyelem!
206
206
</div>
207
207
);
208
208
}
@@ -225,7 +225,7 @@ class Page extends React.Component {
225
225
<div>
226
226
<WarningBanner warn={this.state.showWarning} />
227
227
<button onClick={this.handleToggleClick}>
228
-
{this.state.showWarning ? 'Hide' : 'Show'}
228
+
{this.state.showWarning ? 'Elrejtés' : 'Mutatás'}
229
229
</button>
230
230
</div>
231
231
);
@@ -238,6 +238,6 @@ ReactDOM.render(
238
238
);
239
239
```
240
240
241
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
241
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
242
242
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.
243
+
Ha a komponens`render`metódusában `null` értéket adunk vissza, az nem hat ki a komponens életciklus metódusainak meghívására. Például a`componentDidUpdate`ebben az esetben is meg lesz hívva.
0 commit comments