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/lists-and-keys.md
+47-47
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
1
---
2
2
id: lists-and-keys
3
-
title: Lists and Keys
3
+
title: Listák és kulcsok
4
4
permalink: docs/lists-and-keys.html
5
5
prev: conditional-rendering.html
6
6
next: forms.html
7
7
---
8
8
9
-
First, let's review how you transform lists in JavaScript.
9
+
Először is vegyük át hogyan alakítunk át listákat JavaScript-ben.
10
10
11
-
Given the code below, we use the [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)function to take an array of `numbers` and double their values. We assign the new array returned by `map()`to the variable `doubled`and log it:
11
+
Vegyük az alábbi kódot. A [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)függvény fog egy számokkal teli tömböt (`numbers`) és megduplázza annak értékeit. A `map()`által visszaadott új tömböt hozzárendeljük a `doubled`változóhoz, és kiírjuk a konzolba:
12
12
13
13
```javascript{2}
14
14
const numbers = [1, 2, 3, 4, 5];
15
15
const doubled = numbers.map((number) => number * 2);
16
16
console.log(doubled);
17
17
```
18
18
19
-
This code logs `[2, 4, 6, 8, 10]`to the console.
19
+
Ez a kód a `[2, 4, 6, 8, 10]`tömböt írja ki a konzolba.
20
20
21
-
In React, transforming arrays into lists of [elements](/docs/rendering-elements.html)is nearly identical.
21
+
A React-ben tömböket [elemlistákká](/docs/rendering-elements.html)majdnem ugyanígy transzformálunk.
You can build collections of elements and [include them in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) using curly braces `{}`.
25
+
Elemkollekciókat kapcsos zárójelek segítségével `{}` készíthetsz és [illeszthetsz JSX-be](/docs/introducing-jsx.html#embedding-expressions-in-jsx).
26
26
27
-
Below, we loop through the `numbers`array using the JavaScript[`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)function. We return a `<li>`element for each item. Finally, we assign the resulting array of elements to `listItems`:
27
+
Az alábbiakban egy `numbers`tömbön iterálunk végig a[`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)függvény használatával. Minden elemhez visszaadunk egy `<li>`elemet. Végül hozzárendeljük a kapott elemek tömbjét a `listItems`-hez:
We include the entire `listItems`array inside a`<ul>`element, and [render it to the DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
36
+
A `listItems`tömböt belefoglaljuk egy`<ul>`elembe, és [azt a DOM-ba rendereljük](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
37
37
38
38
```javascript{2}
39
39
ReactDOM.render(
@@ -42,15 +42,15 @@ ReactDOM.render(
42
42
);
43
43
```
44
44
45
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
45
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
46
46
47
-
This code displays a bullet list of numbers between 1 and 5.
47
+
Ez a kód egy pontokba szedett számlistát mutat 1-től 5-ig.
48
48
49
-
### Basic List Component {#basic-list-component}
49
+
### Alap lista komponens {#basic-list-component}
50
50
51
-
Usually you would render lists inside a [component](/docs/components-and-props.html).
51
+
Listákat általában egy [komponensbe](/docs/components-and-props.html) szeretnénk renderelni.
52
52
53
-
We can refactor the previous example into a component that accepts an array of `numbers`and outputs a list of elements.
53
+
Az előző példát át tudjuk alakítani egy komponenssé, ami fogad egy `numbers`tömböt, és egy elemlistát ad vissza.
54
54
55
55
```javascript{3-5,7,13}
56
56
function NumberList(props) {
@@ -70,9 +70,9 @@ ReactDOM.render(
70
70
);
71
71
```
72
72
73
-
When you run this code, you'll be given a warning that a key should be provided for list items. A "key" is a special string attribute you need to include when creating lists of elements. We'll discuss why it's important in the next section.
73
+
Ha ezt a kódot futtatod, egy figyelmeztetést fogsz kapni, hogy minden listaelemnek rendelkeznie kell egy kulccsal. A "key" (kulcs) egy speciális szöveges attribútum, amit fel kell vegyél ha listaelemeket készítesz. A következő szekcióban megbeszéljük hogy ez miért is fontos.
74
74
75
-
Let's assign a`key` to our list items inside `numbers.map()` and fix the missing key issue.
75
+
Rendeljünk hozzá egy`key`-t a listaelemeinkhez a `numbers.map()`-en belül, hogy kijavítsuk a kulcs problémát.
76
76
77
77
```javascript{4}
78
78
function NumberList(props) {
@@ -94,11 +94,11 @@ ReactDOM.render(
94
94
);
95
95
```
96
96
97
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
97
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
98
98
99
-
## Keys {#keys}
99
+
## Kulcsok {#keys}
100
100
101
-
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:
101
+
A kulcsok segítenek a React-nek azonosítani, hogy mely elemek változtak, lettek hozzáadva, vagy épp törölve. A kulcsokat a tömbön belül kell az elemekhez hozzárendelnünk a stabil azonosíthatóság érdekében:
The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:
112
+
A legjobb módja egy kulcs választásának ha egy szöveget használunk, ami egyedien azonosít egy listaelemet annak testvérei között. Leggyakrabban az adatod ID azonosítókulcsa lehet a legjobb kulcs:
When you don't have stable IDs for rendered items, you may use the item index as a key as a last resort:
122
+
Ha nincs egy stabil ID azonosítókulcsod a renderelt elemekhez, akkor használhatod az elemindexet is kulcsként utolsó lehetőségként:
123
123
124
124
```js{2,3}
125
125
const todoItems = todos.map((todo, index) =>
126
-
// Only do this if items have no stable IDs
126
+
// Csak akkor tedd ezt, ha nincs egy stabil ID azonosítókulcsod
127
127
<li key={index}>
128
128
{todo.text}
129
129
</li>
130
130
);
131
131
```
132
132
133
-
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an [in-depth explanation on the negative impacts of using an index as a key](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). If you choose not to assign an explicit key to list items then React will default to using indexes as keys.
133
+
Ha az elemek sorrendje változhat, akkor nem ajánljuk indexek használatát kulcsként. Ez negatívan hathat ki a teljesítményre és problémákat okozhat a komponens állapotában. Nézd meg Robin Pokorny' cikkét egy [mélyebbre ható magyarázatért, az index mint kulcs használatáról](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). Ha úgy döntesz, hogy nem rendelsz egy explicit kulcsot a listaelemekhez, a React automatikusan az indexet fogja kulcsként használni.
134
134
135
-
Here is an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children)if you're interested in learning more.
135
+
Itt egy [mélyebbre ható magyarázat, hogy miért is fontosak a kulcsok](/docs/reconciliation.html#recursing-on-children)ha többet szeretnél tanulni.
136
136
137
-
### Extracting Components with Keys {#extracting-components-with-keys}
Keys only make sense in the context of the surrounding array.
139
+
A kulcsoknak csak a környező tömb kontextusában van értelmük.
140
140
141
-
For example, if you [extract](/docs/components-and-props.html#extracting-components)a`ListItem`component, you should keep the key on the `<ListItem />`elements in the array rather than on the `<li>`element in the `ListItem` itself.
141
+
Például ha [kivonsz](/docs/components-and-props.html#extracting-components)egy`ListItem`komponenst, a kulcsot a `<ListItem />`elemen kell hogy tartsd, nem pedig áttenni azt az `<li>`elemre a `ListItem`-en belül.
142
142
143
-
**Example: Incorrect Key Usage**
143
+
**Példa: Helytelen kulcshasználat**
144
144
145
145
```javascript{4,5,14,15}
146
146
function ListItem(props) {
147
147
const value = props.value;
148
148
return (
149
-
// Wrong! There is no need to specify the key here:
149
+
// Hibás! Itt a kulcs definiálásának nincs semmi értelme:
150
150
<li key={value.toString()}>
151
151
{value}
152
152
</li>
@@ -156,7 +156,7 @@ function ListItem(props) {
156
156
function NumberList(props) {
157
157
const numbers = props.numbers;
158
158
const listItems = numbers.map((number) =>
159
-
// Wrong! The key should have been specified here:
159
+
// Hibás! A kulcsot itt kell definiálni:
160
160
<ListItem value={number} />
161
161
);
162
162
return (
@@ -173,18 +173,18 @@ ReactDOM.render(
173
173
);
174
174
```
175
175
176
-
**Example: Correct Key Usage**
176
+
**Példa: Helyes kulcshasználat**
177
177
178
178
```javascript{2,3,9,10}
179
179
function ListItem(props) {
180
-
// Correct! There is no need to specify the key here:
180
+
// Helyes! Itt a kulcs definiálásának nincs semmi értelme:
181
181
return <li>{props.value}</li>;
182
182
}
183
183
184
184
function NumberList(props) {
185
185
const numbers = props.numbers;
186
186
const listItems = numbers.map((number) =>
187
-
// Correct! Key should be specified inside the array.
187
+
// Helyes! A kulcsot itt kell definiálni:
188
188
<ListItem key={number.toString()}
189
189
value={number} />
190
190
);
@@ -202,13 +202,13 @@ ReactDOM.render(
202
202
);
203
203
```
204
204
205
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
205
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
206
206
207
-
A good rule of thumb is that elements inside the `map()` call need keys.
207
+
Egy jó ökölszabály, hogy a `map()`-en belül lévő minden elemnek rendelkeznie kell egy kulccsal.
208
208
209
-
### Keys Must Only Be Unique Among Siblings {#keys-must-only-be-unique-among-siblings}
209
+
### A kulcsoknak csak testvéreik között kell egyedinek lenniük {#keys-must-only-be-unique-among-siblings}
210
210
211
-
Keys used within arrays should be unique among their siblings. However they don't need to be globally unique. We can use the same keys when we produce two different arrays:
211
+
A kulcsoknak egyedinek kell lenniük testvéreik között. Azonban nem kell, hogy globálisan is egyediek legyenek. Ugyanazokat a kulcsokat használhatjuk két különböző tömb készítése esetén:
212
212
213
213
```js{2,5,11,12,19,21}
214
214
function Blog(props) {
@@ -237,18 +237,18 @@ function Blog(props) {
237
237
}
238
238
239
239
const posts = [
240
-
{id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
241
-
{id: 2, title: 'Installation', content: 'You can install React from npm.'}
{id: 2, title: 'Telepítés', content: 'A React-et npm-ből tudod telepíteni.'}
242
242
];
243
243
ReactDOM.render(
244
244
<Blog posts={posts} />,
245
245
document.getElementById('root')
246
246
);
247
247
```
248
248
249
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
249
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
250
250
251
-
Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:
251
+
A kulcsok a React számára szolgálnak utalásként, de leküldve nem lesznek a komponenseidnek. Ha ugyanarra az értékre van szükséged a komponensedben is, akkor azt egy másik prop névvel is explicit módon meg kell adnod:
With the example above, the `Post`component can read`props.id`, but not`props.key`.
262
+
A fenti példával a `Post`komponens olvasni tudja`props.id`-t, de a`props.key`-t nem.
263
263
264
-
### Embedding map() in JSX {#embedding-map-in-jsx}
264
+
### map() JSX-be ágyazása {#embedding-map-in-jsx}
265
265
266
-
In the examples above we declared a separate `listItems`variable and included it in JSX:
266
+
A fenti példákban külön deklaráltuk a `listItems`változót és belevettük azt a JSX-be:
267
267
268
268
```js{3-6}
269
269
function NumberList(props) {
@@ -280,7 +280,7 @@ function NumberList(props) {
280
280
}
281
281
```
282
282
283
-
JSX allows [embedding any expression](/docs/introducing-jsx.html#embedding-expressions-in-jsx)in curly braces so we could inline the `map()`result:
283
+
A JSX lehetővé teszi [bármilyen kifejezés beágyazását](/docs/introducing-jsx.html#embedding-expressions-in-jsx)kapcsos zárójelek között, így a `map()`eredményét is:
284
284
285
285
```js{5-8}
286
286
function NumberList(props) {
@@ -296,6 +296,6 @@ function NumberList(props) {
296
296
}
297
297
```
298
298
299
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
299
+
[**Próbáld ki a CodePen-en**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
300
300
301
-
Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the `map()`body is too nested, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
301
+
Ennek néha tisztább kód az eredménye, de ezzel a stílussal könnyű visszaélni. Ahogy a JavaScript-ben is, tőled függ hogy megéri-e kivonni egy változót az olvashatóság érdekében. Tartsd észben hogy ha a `map()`teste túl beágyazott, talán itt az ideje [kivonni egy komponenst](/docs/components-and-props.html#extracting-components).
0 commit comments