Skip to content

Commit 000a3d4

Browse files
committed
docs: translate third section
1 parent 1ece78f commit 000a3d4

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/content/learn/rendering-lists.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -266,31 +266,31 @@ const listItems = chemists.map(person => { // Kurung kurawal
266266

267267
</Pitfall>
268268

269-
## Keeping list items in order with `key` {/*keeping-list-items-in-order-with-key*/}
269+
## Menjaga urutan dengan `key` {/*keeping-list-items-in-order-with-key*/}
270270

271-
Notice that all the sandboxes above show an error in the console:
271+
Perhatikan bahwa setiap *sandbox* di atas menampilkan pesan kesalahan:
272272

273273
<ConsoleBlock level="error">
274274

275275
Warning: Each child in a list should have a unique "key" prop.
276276

277277
</ConsoleBlock>
278278

279-
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+
Anda harus memberikan setiap anggota dari seranai sebuah `key`--sebuah *string* atau angka yang dapat mengidentifikasi setiap anggota secara unik:
280280

281281
```js
282282
<li key={person.id}>...</li>
283283
```
284284

285285
<Note>
286286

287-
JSX elements directly inside a `map()` call always need keys!
287+
Setiap elemen JSX yang ada di dalam `map()` harus selalu memiliki `key`!
288288

289289
</Note>
290290

291-
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+
`Key` memberi tahu React mengenai hubungan antara sebuah komponen dengan sebuah anggota seranai. Hal ini krusial jika anggota seranai bisa berubah posisi (contohnya karena proses pengurutan (*sorting*)), ditambah, atau dihapus. Sebuah `key` yang baik dapat membantu React untuk mengetahui apa yang telah terjadi dan menentukan langkah optimal saat memperbarui pohon DOM.
292292

293-
Rather than generating keys on the fly, you should include them in your data:
293+
Sebaiknya, `key` terkandung di dalam data Anda:
294294

295295
<Sandpack>
296296

@@ -318,31 +318,31 @@ export default function List() {
318318

319319
```js data.js active
320320
export const people = [{
321-
id: 0, // Used in JSX as a key
321+
id: 0, // Digunakan sebagai key pada JSX
322322
name: 'Creola Katherine Johnson',
323323
profession: 'mathematician',
324324
accomplishment: 'spaceflight calculations',
325325
imageId: 'MK3eW3A'
326326
}, {
327-
id: 1, // Used in JSX as a key
327+
id: 1, // Digunakan sebagai key pada JSX
328328
name: 'Mario José Molina-Pasquel Henríquez',
329329
profession: 'chemist',
330330
accomplishment: 'discovery of Arctic ozone hole',
331331
imageId: 'mynHUSa'
332332
}, {
333-
id: 2, // Used in JSX as a key
333+
id: 2, // Digunakan sebagai key pada JSX
334334
name: 'Mohammad Abdus Salam',
335335
profession: 'physicist',
336336
accomplishment: 'electromagnetism theory',
337337
imageId: 'bE7W1ji'
338338
}, {
339-
id: 3, // Used in JSX as a key
339+
id: 3, // Digunakan sebagai key pada JSX
340340
name: 'Percy Lavon Julian',
341341
profession: 'chemist',
342342
accomplishment: 'pioneering cortisone drugs, steroids and birth control pills',
343343
imageId: 'IOjWm71'
344344
}, {
345-
id: 4, // Used in JSX as a key
345+
id: 4, // Digunakan sebagai key pada JSX
346346
name: 'Subrahmanyan Chandrasekhar',
347347
profession: 'astrophysicist',
348348
accomplishment: 'white dwarf star mass calculations',
@@ -376,11 +376,11 @@ img { width: 100px; height: 100px; border-radius: 50%; }
376376

377377
<DeepDive>
378378

379-
#### Displaying several DOM nodes for each list item {/*displaying-several-dom-nodes-for-each-list-item*/}
379+
#### Menampilkan beberapa *node* DOM untuk setiap anggota seranai {/*displaying-several-dom-nodes-for-each-list-item*/}
380380

381-
What do you do when each item needs to render not one, but several DOM nodes?
381+
Bagaimana kalau setiap anggota seranai membutuhkan bukan hanya satu, tetapi beberapa *node* DOM?
382382

383-
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+
Sintaks singkat [`<>...</>` Fragment](/reference/react/Fragment) tidak memberikan tempat untuk `key`, sehingga Anda harus membungkus ke dalam sebuah `<div>` atau menggunakan [sintaks `<Fragment>` yang lebih panjang](/reference/react/Fragment#rendering-a-list-of-fragments):
384384

385385
```js
386386
import { Fragment } from 'react';
@@ -395,35 +395,35 @@ const listItems = people.map(person =>
395395
);
396396
```
397397

398-
Fragments disappear from the DOM, so this will produce a flat list of `<h1>`, `<p>`, `<h1>`, `<p>`, and so on.
398+
Pada akhirnya, `Fragment` akan hilang dari DOM dan hanya menyisakan `<h1>`, `<p>`, `<h1>`, `<p>`, dan seterusnya, pada contoh di atas.
399399

400400
</DeepDive>
401401

402-
### Where to get your `key` {/*where-to-get-your-key*/}
402+
### Bagaimana Anda memperoleh `key`? {/*where-to-get-your-key*/}
403403

404-
Different sources of data provide different sources of keys:
404+
Sumber data yang berbeda akan memberikan `key` yang berbeda juga, contoh:
405405

406-
* **Data from a database:** If your data is coming from a database, you can use the database keys/IDs, which are unique by nature.
407-
* **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+
* **Data dari basis data:** Jika data yang digunakan berasal dari basis data, ID dapat digunakan sebagai `key` karena sifatnya yang sudah unik.
407+
* **Data lokal:** Jika data dihasilkan dan disimpan secara lokal (seperti catatan pada aplikasi penulisan catatan), Anda dapat menggunakan *counter* yang bertambah, [`crypto.randomUUID()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID), atau *library* seperti [`uuid`](https://www.npmjs.com/package/uuid).
408408

409-
### Rules of keys {/*rules-of-keys*/}
409+
### Aturan `key` {/*rules-of-keys*/}
410410

411-
* **Keys must be unique among siblings.** However, it’s okay to use the same keys for JSX nodes in _different_ arrays.
412-
* **Keys must not change** or that defeats their purpose! Don't generate them while rendering.
411+
* **`Key` harus bersifat unik antar-*sibling*.** Namun, `key` yang sama bisa digunakan lagi di seranai yang berbeda.
412+
* **`Key` tidak boleh berubah** atau fungsinya akan hilang! Jangan membuat `key` di saat me-*render*.
413413

414-
### Why does React need keys? {/*why-does-react-need-keys*/}
414+
### Mengapa React membutuhkan `key`? {/*why-does-react-need-keys*/}
415415

416-
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+
Bayangkan jika *file* yang ada di komputer Anda tidak memiliki nama. Sebagai pengganti, Anda merujuk ke *file* tersebut dengan urutannya--file pertama, file kedua, dan seterusnya. Saat *file* pertama dihapus, *file* kedua akan menjadi *file* pertama, kemudian *file* ketiga akan menjadi *file* kedua, dan seterusnya. Perujukan *file* menjadi tidak konsisten.
417417

418-
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+
Nama file pada folder dan `key` pada JSX memiliki tujuan yang serupa. Mereka membantu kita mengidentifikasi anggota seranai dan membedakan mereka antar-*sibling*. `Key` yang baik tidak hanya memberikan informasi mengenai posisi *item* di dalam seranai, tetapi juga membantu React mengidentifikasi *item* tersebut sepanjang hidupnya.
419419

420420
<Pitfall>
421421

422-
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+
Anda mungkin tertarik untuk menggunakan indeks pada seranai sebagai `key`. Sebenarnya, itulah yang digunakan React jika Anda tidak memberikan `key`. Namun, urutan anggota seranai dapat berubah saat ada yang ditambah, dihapus, atau diubah urutannya. Jika ini terjadi, ini bisa menimbulkan *bug* yang membingungkan dan sulit ditemukan.
423423

424-
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+
Bukan hanya itu, sebaiknya juga tidak membuat `key` sembarangan, misal `key={Math.random()}`. Hal ini menyebabkan `key` baru dibuat setiap *render*. Akibatnya, komponen dan DOM juga ikut dibuat baru setiap *render*. Pada akhirnya, proses *render* akan menjadi lambat dan masukan dari pengguna juga akan hilang. Oleh karena itu, sebaiknya Anda menggunakan ID yang konsisten yang berasal dari data.
425425

426-
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+
Perlu diperhatikan bahwa komponen tidak bisa membaca `key`, layaknya sebuah *prop*. `Key` hanya digunakan oleh React. Jika komponen Anda membutuhkan ID, Anda harus menggunakan *prop* yang berbeda, contoh `<Profile key={id} userId={id} />`.
427427

428428
</Pitfall>
429429

0 commit comments

Comments
 (0)