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: src/content/learn/rendering-lists.md
+62-60Lines changed: 62 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: Rendering Lists
2
+
title: Listeleri Render Etmek
3
3
---
4
4
5
5
<Intro>
6
6
7
-
You will often want to display multiple similar components from a collection of data. You can use the [JavaScript array methods](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#)to manipulate an array of data. On this page, you'll use[`filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)and[`map()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map)with React to filter and transform your array of data into an array of components.
7
+
Genellikle bir veri topluluğundan birden fazla bileşen göstermek isteyeceksiniz. Bir veri dizisini manipule etmek için [JavaScript dizi metodlarını](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#)kullanabilirsiniz. Bu sayfada, React ile[`filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)ve[`map()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map)metodlarını kullanarak bir veri dizisini filtreleyecek ve bir bileşen dizisine dönüştüreceksiniz.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*How to render components from an array using JavaScript's `map()`
14
-
*How to render only specific components using JavaScript's `filter()`
15
-
*When and why to use React keys
13
+
*Javascript'in `map()` metodunu kullanarak bir diziden nasıl bileşenler oluşturulur?
14
+
*Javascript'in `filter()` metodunu kullanarak yalnızca belirli bileşenler nasıl oluşturulur?
15
+
*React anahtarlarını ne zaman ve neden kullanmalı?
16
16
17
17
</YouWillLearn>
18
18
19
-
## Rendering data from arrays {/*rendering-data-from-arrays*/}
19
+
## Dizilerden veri render etmek {/*rendering-data-from-arrays*/}
20
20
21
-
Say that you have a list of content.
21
+
Aşağıdaki gibi bir içerik listeniz olduğunu düşünelim.
22
22
23
23
```js
24
24
<ul>
@@ -30,11 +30,12 @@ Say that you have a list of content.
30
30
</ul>
31
31
```
32
32
33
-
The only difference among those list items is their contents, their data. You will often need to show several instances of the same component using different data when building interfaces: from lists of comments to galleries of profile images. In these situations, you can store that data in JavaScript objects and arrays and use methods like [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)and[`filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)to render lists of components from them.
33
+
Bu liste öğeleri arasındaki tek fark içerikleri, verileridir. Arayüzler oluştururken farklı veriler kullanan aynı bileşenin birkaç örneğini göstermeniz gerekebilir: yorum listelerinden profil resimleri galerilerine kadar. Bu gibi durumlarda, gerekli verileri Javascript objeleri ve dizilerinde saklayabilir ve [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)ve[`filter()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)gibi metodları kullanarak bu verilerden bileşen listeleri oluşturabilirsiniz.
34
34
35
-
Here’s a short example of how to generate a list of items from an array:
35
+
Aşağıdaki kısa örnekte bir diziden nasıl öğe listesi oluşturulduğunu görebilirsiniz.
36
36
37
-
1.**Move** the data into an array:
37
+
38
+
1.**Aktar** veriyi bir dizi içine:
38
39
39
40
```js
40
41
constpeople= [
@@ -46,19 +47,19 @@ const people = [
46
47
];
47
48
```
48
49
49
-
2.**Map**the `people`members into a new array of JSX nodes, `listItems`:
50
+
2.**Map**metodu ile `people`üyelerini `listItems` adında yeni bir JSX node dizisiyle eşleştirin:
Let's say you want a way to only show people whose profession is `'chemist'`. You can use JavaScript's`filter()`method to return just those people. This method takes an array of items, passes them through a “test” (a function that returns `true` or `false`), and returns a new array of only those items that passed the test (returned `true`).
125
+
Diyelim ki sadece mesleği `'chemist'` olan kişileri göstermenin bir yolunu istiyorsunuz. Javacript'in`filter()`metodunu kullanarak yalnızca bu kişileri döndürebilirsiniz. Bu yöntem, bir öğe dizisini alır, onları bir "testten" (`doğru` veya `yanlış` döndüren bir test) geçirir ve yalnızca testi geçen (`doğru` olarak döndürülen) öğelerden oluşan yeni bir dizi döndürür.
125
126
126
-
You only want the items where `profession` is `'chemist'`. The "test" function for this looks like `(person) => person.profession === 'chemist'`. Here's how to put it together:
127
+
Sadece mesleği `'chemist'` olan kişileri istiyorsunuz. Bunun için "test" fonksiyonu `(person) => person.profession === 'chemist'` şeklindedir. Bunu nasıl bir araya getireceğiniz aşağıda gösterilmiştir:
127
128
128
-
1.**Create** a new array of just “chemist” people, `chemists`, by calling`filter()`on the `people`filtering by `person.profession === 'chemist'`:
129
+
1.Sadece "kimyacı" mesleğindeki insanlardan yeni bir `chemists` dizisi **oluştur**, bunun için`filter()`metodu `people`dizisinde `person.profession === 'chemist'` şeklinde kullanılır:
129
130
130
131
```js
131
132
constchemists=people.filter(person=>
132
133
person.profession==='chemist'
133
134
);
134
135
```
135
136
136
-
2.Now **map**over `chemists`:
137
+
2.Şimdi `chemists` dizisinde **map**metodu kullanılır:
Arrow functions containing `=> {`are said to have a ["block body".](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#function_body)They let you write more than a single line of code, but you *have to* write a `return`statement yourself. If you forget it, nothing gets returned!
265
+
`=> {`içeren ok fonksiyonların bir ["blok gövdesi".](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#function_body)olduğu söylenir. Ok fonksiyonları tek bir kod satırından daha fazlasını yazmanıza olanak verir ancak `return`ifadesini yazmanız gerekmektedir. Eğer unutursanız, fonksiyonunuz geri hiçbir şey döndürmez!
264
266
265
267
</Pitfall>
266
268
267
-
## Keeping list items in order with `key` {/*keeping-list-items-in-order-with-key*/}
269
+
## `anahtar` ile liste öğelerini sıralı tutmak {/*keeping-list-items-in-order-with-key*/}
268
270
269
-
Notice that all the sandboxes above show an error in the console:
271
+
Yukarıdaki tüm sandboxların konsolda bir hata gösterdiğine dikkat edin:
270
272
271
273
<ConsoleBlocklevel="error">
272
274
273
-
Warning: Each child in a list should have a unique "key" prop.
275
+
Uyarı: Bir listedeki her alt elemanın benzersiz bir "anahtar" prop'u olmalıdır.
274
276
275
277
</ConsoleBlock>
276
278
277
-
You need to give each array item a `key`-- a string or a number that uniquely identifies it among other items in that array:
279
+
Herbir dizi öğesine bir `anahtar` vermelisiniz -- dizideki herbir öğeyi birbirinden ayırt edecek şekilde o öğeye bir string ya da numara vermeniz gerekmektedir:
278
280
279
281
```js
280
282
<li key={person.id}>...</li>
281
283
```
282
284
283
285
<Note>
284
286
285
-
JSX elements directly inside a `map()`call always need keys!
287
+
Her `map()`metodu kullanıldığında JSX elementleri bir anahtara ihtiyaç duyar.
286
288
287
289
</Note>
288
290
289
-
Keys tell React which array item each component corresponds to, so that it can match them up later. This becomes important if your array items can move (e.g. due to sorting), get inserted, or get deleted. A well-chosen `key` helps React infer what exactly has happened, and make the correct updates to the DOM tree.
291
+
Anahtarlar, React'e her bir bileşenin hangi dizi öğesine karşılık geldiğini söylerek React'in daha sonra bu öğeleri eşleştirmesini sağlar. Bu durum, eğer dizi öğeleriniz yer değiştiriyorsa (örneğin sıralaması değişiyorsa), yeni öğeler eklenip veya çıkartılabiliyorsa daha önemli bir hale gelir. İyi seçilmiş bir `anahtar`React'in değişen öğelerde ne olduğunu anlamasına ve DOM ağacında doğru güncellemeleri yapmasına yardımcı olur.
290
292
291
-
Rather than generating keys on the fly, you should include them in your data:
293
+
Anında anahtar oluşturmak yerine, anahtarları verilerinize dahil etmelisiniz:
292
294
293
295
<Sandpack>
294
296
@@ -316,31 +318,31 @@ export default function List() {
316
318
317
319
```js data.js active
318
320
exportconstpeople= [{
319
-
id:0, //Used in JSX as a key
321
+
id:0, // JSX için anahtar olarak kullanılır
320
322
name:'Creola Katherine Johnson',
321
323
profession:'mathematician',
322
324
accomplishment:'spaceflight calculations',
323
325
imageId:'MK3eW3A'
324
326
}, {
325
-
id:1, //Used in JSX as a key
327
+
id:1, // JSX için anahtar olarak kullanılır
326
328
name:'Mario José Molina-Pasquel Henríquez',
327
329
profession:'chemist',
328
330
accomplishment:'discovery of Arctic ozone hole',
329
331
imageId:'mynHUSa'
330
332
}, {
331
-
id:2, //Used in JSX as a key
333
+
id:2, // JSX için anahtar olarak kullanılır
332
334
name:'Mohammad Abdus Salam',
333
335
profession:'physicist',
334
336
accomplishment:'electromagnetism theory',
335
337
imageId:'bE7W1ji'
336
338
}, {
337
-
id:3, //Used in JSX as a key
339
+
id:3, // JSX için anahtar olarak kullanılır
338
340
name:'Percy Lavon Julian',
339
341
profession:'chemist',
340
342
accomplishment:'pioneering cortisone drugs, steroids and birth control pills',
341
343
imageId:'IOjWm71'
342
344
}, {
343
-
id:4, //Used in JSX as a key
345
+
id:4, // JSX için anahtar olarak kullanılır
344
346
name:'Subrahmanyan Chandrasekhar',
345
347
profession:'astrophysicist',
346
348
accomplishment:'white dwarf star mass calculations',
#### Displaying several DOM nodes for each list item {/*displaying-several-dom-nodes-for-each-list-item*/}
379
+
#### Her liste öğesi için birkaç DOM node'u göstermek {/*displaying-several-dom-nodes-for-each-list-item*/}
378
380
379
-
What do you do when each item needs to render not one, but several DOM nodes?
381
+
Her öğenin bir değil birkaç DOM node'u render etmesi gerektiğinde ne yaparsınız?
380
382
381
-
The short [`<>...</>` Fragment](/reference/react/Fragment) syntax won't let you pass a key, so you need to either group them into a single `<div>`, or use the slightly longer and [more explicit `<Fragment>` syntax:](/reference/react/Fragment#rendering-a-list-of-fragments)
383
+
Kısa [`<>...</>` Fragment](/reference/react/Fragment) syntax'ı bir anahtar belirlemenize izin vermez, bu nedenle tüm elementleri bir `<div>` elementi içinde gruplandırmanız ya da daha uzun olan [`<Fragment>` syntax'i](/reference/react/Fragment#rendering-a-list-of-fragments) kullanmalısınız.
Fragments disappear from the DOM, so this will produce a flat list of `<h1>`, `<p>`, `<h1>`, `<p>`, and so on.
398
+
Fragmentler DOM'dan kaybolur, bu nedenle `<h1>`, `<p>`, `<h1>`, `<p>` gibi elementlerden oluşan düz bir liste oluşturulur.
397
399
398
400
</DeepDive>
399
401
400
-
### Where to get your `key` {/*where-to-get-your-key*/}
402
+
### `anahtar` nereden gelir {/*where-to-get-your-key*/}
401
403
402
-
Different sources of data provide different sources of keys:
404
+
Farklı veri kaynakları, farklı anahtar kaynakları sağlar:
403
405
404
-
***Data from a database:**If your data is coming from a database, you can use the database keys/IDs, which are unique by nature.
405
-
***Locally generated data:**If your data is generated and persisted locally (e.g. notes in a note-taking app), use an incrementing counter,[`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)or a package like [`uuid`](https://www.npmjs.com/package/uuid)when creating items.
406
+
***Veritabanından gelen veri:**Eğer veriniz bir veritabanından geliyorsa, doğasında ötürü zaten benzersiz olan veritabanı anahtarları/ID'leri kullanılabilir.
407
+
***Yerel olarak oluşturulmuş veriler:**Eğer veriniz yerel olarak oluşturuluyor ve saklanıyorsa (örneğin not alma aplikasyonundaki notlar), sıralı olarak artan numaralar[`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)ya da [`uuid`](https://www.npmjs.com/package/uuid)gibi bir paket kullanabilirsiniz.
406
408
407
-
### Rules of keys {/*rules-of-keys*/}
409
+
### Anahtarların kuralları {/*rules-of-keys*/}
408
410
409
-
***Keys must be unique among siblings.**However, it’s okay to use the same keys for JSX nodes in _different_ arrays.
410
-
***Keys must not change**or that defeats their purpose! Don't generate them while rendering.
411
+
***Anahtarl kardeşler arasında benzersiz olmalıdır.**Ancak, _different_ dizilerdeki JSX node'ları için aynı anahtarları kullanmakta bir sakınca yoktur.
412
+
***Anahtarlar değişmemelidir.**yoksa bu anahtarların bütün amacını bozar! Anahtarları render etme sırasında üretmeyiniz.
411
413
412
-
### Why does React need keys? {/*why-does-react-need-keys*/}
414
+
### React neden anahtarlara ihtiyaç duyar? {/*why-does-react-need-keys*/}
413
415
414
-
Imagine that files on your desktop didn't have names. Instead, you'd refer to them by their order -- the first file, the second file, and so on. You could get used to it, but once you delete a file, it would get confusing. The second file would become the first file, the third file would be the second file, and so on.
416
+
Masaüstünüzdeki dosyaların isimlerinin olmadığını düşünün. Imagine that files on your desktop didn't have names. Bunun yerine, dosyalara sıralarına göre refere edersiniz -- ilk dosya, ikinci dosya gibi. Bu sisteme alışabilirsiniz ama bir dosyayı sildiğiniz zaman durum kafa karıştırıcı bir hale gelirdi. İkinci dosya birinci, üçüncü dosya ise ikinci dosya olurdu gibi.
415
417
416
-
File names in a folder and JSX keys in an array serve a similar purpose. They let us uniquely identify an item between its siblings. A well-chosen key provides more information than the position within the array. Even if the _position_changes due to reordering, the `key` lets React identify the item throughout its lifetime.
418
+
Dosya isimleri de dizilerdeki JSX anahtarları aynı amaca hizmet etmektedir. Anahtarlar, kardeşleri arasında bir öğeyi benzersiz bir şekilde tanımlamamıza olanak sağlar. İyi seçilmiş bir anahtar, dizi içindeki pozisyondan daha fazla bilgi sağlar. Öğenin _position_yeniden sıralama nedeniyle değişse bile, `anahtar`React'in öğeyi döngü boyunca tanımasını sağlar.
417
419
418
420
<Pitfall>
419
421
420
-
You might be tempted to use an item's index in the array as its key. In fact, that's what React will use if you don't specify a `key` at all. But the order in which you render items will change over time if an item is inserted, deleted, or if the array gets reordered. Index as a key often leads to subtle and confusing bugs.
422
+
Anahtar olarak dizideki bir öğenin dizinini kullanmak isteyebilirsiniz. Aslında, hiç bir `anahtar` belirtmezseniz React'in kullanacağı anahtar budur. Ancak, bir öğe eklenirse, silinirse veya dizi yeniden sıralanırsa, öğeleri oluşturma sıranız zaman içinde değişecektir. Bir anahtar olarak dizin, genellikle gizli ve kafa karıştırıcı hatalara yol açar.
421
423
422
-
Similarly, do not generate keys on the fly, e.g. with `key={Math.random()}`. This will cause keys to never match up between renders, leading to all your components and DOM being recreated every time. Not only is this slow, but it will also lose any user input inside the list items. Instead, use a stable ID based on the data.
424
+
Benzer şekilde, anahtarları o anda oluşturmayın, örneğin `anahtar={Math.random()}` ile oluşturulan anahtarlar. Bu, anahtarların render etmeler arasında eşleşmemesine neden olarak tüm bileşenlerinizin ve DOM'un her seferinde yeniden oluşturulmasına yol açar. Bu sadece yavaş olmakla kalmaz, aynı zamanda liste öğeleri içindeki herhangi bir kullanıcı girdisini de kaybeder. Bunun yerine, verilere dayalı sabit bir ID kullanılmalıdır.
423
425
424
-
Note that your components won't receive `key` as a prop. It's only used as a hint by React itself. If your component needs an ID, you have to pass it as a separate prop: `<Profile key={id} userId={id} />`.
426
+
Bileşenlerinizin prop olarak `anahtar` almayacağını unutmayın. Yalnıcaz React'in kendisi tarafından bir işaret olarak kullanılırlar. Eğer bileşeninizin bir ID'ye ihtiyacı varsa, ID'yi ayrı bir prop olarak şu şekilde kullanabilirsiniz: `<Profile key={id} userId={id} />`.
425
427
426
428
</Pitfall>
427
429
428
430
<Recap>
429
431
430
-
On this page you learned:
432
+
Bu sayfada şunları öğrendiniz:
431
433
432
-
*How to move data out of components and into data structures like arrays and objects.
433
-
*How to generate sets of similar components with JavaScript's`map()`.
434
-
*How to create arrays of filtered items with JavaScript's`filter()`.
435
-
*Why and how to set `key` on each component in a collection so React can keep track of each of them even if their position or data changes.
434
+
*Verileri bileşenlerin dışına, diziler ve objeler gibi veri yapılarına taşıma.
435
+
* JavaScript'in`map()` metodu ile benzer bileşen setleri oluşturma.
436
+
* JavaScript'in`filter()` metodu ile filterenmiş öğe dizileri oluşturma.
437
+
*React'in, konumları ya da verileri değişse bile her bir koleksiyondaki her bileşeni takip edebilmesi için `anahtar` neden ve nasıl kullanılır.
0 commit comments