Skip to content

Commit 4ef6f3c

Browse files
committed
docs: translate recap and challenges
1 parent 3bf81d4 commit 4ef6f3c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/content/learn/keeping-components-pure.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,29 @@ Setiap fitur baru React yang kami bangun memanfaatkan kelebihan dari kemurnian.
215215

216216
<Recap>
217217

218-
* A component must be pure, meaning:
219-
* **It minds its own business.** It should not change any objects or variables that existed before rendering.
220-
* **Same inputs, same output.** Given the same inputs, a component should always return the same JSX.
221-
* Rendering can happen at any time, so components should not depend on each others' rendering sequence.
222-
* You should not mutate any of the inputs that your components use for rendering. That includes props, state, and context. To update the screen, ["set" state](/learn/state-a-components-memory) instead of mutating preexisting objects.
223-
* Strive to express your component's logic in the JSX you return. When you need to "change things", you'll usually want to do it in an event handler. As a last resort, you can `useEffect`.
224-
* Writing pure functions takes a bit of practice, but it unlocks the power of React's paradigm.
218+
* Sebuah komponen harus murni, berarti:
219+
* **Dia hanya mengurus dirinya sendiri.** Dia tidak mengubah objek atau variabel yang ada sebelum dia dipanggil.
220+
* **Masukan yang sama, luaran yang sama.** Untuk masukan yang sama, fungsi murni akan selalu menghasilkan JSX yang sama.
221+
* *Render* bisa terjadi kapan saja, maka komponen sebaiknya tidak bergantung terhadap proses *render* satu sama lain.
222+
* Anda sebaiknya tidak memutasi masukan yang digunakan komponen Anda dalam proses *render*, termasuk *prop*, *state*, dan *context*. Untuk memperbarui layar, ["ubah" *state*](/learn/state-a-components-memory) daripada memutasi objek yang sudah ada sebelumnya.
223+
* Anda sebaiknya berusaha untuk menuliskan logika komponen di JSX yang akan dihasilkan komponen. Saat Anda ingin "mengubah sesuatu", Anda sebaiknya melakukannya di dalam *event handler*. Sebagai pilihan terakhir, Anda juga bisa menggunakan `useEffect`.
224+
* Menulis fungsi murni akan membutuhkan waktu, tetapi ini membuka jalan untuk memanfaatkan potensi paradigma React secara maksimal.
225225

226226
</Recap>
227227

228228

229229

230230
<Challenges>
231231

232-
#### Fix a broken clock {/*fix-a-broken-clock*/}
232+
#### Memperbaiki jam rusak {/*fix-a-broken-clock*/}
233233

234-
This component tries to set the `<h1>`'s CSS class to `"night"` during the time from midnight to six hours in the morning, and `"day"` at all other times. However, it doesn't work. Can you fix this component?
234+
Komponen ini ingin mengubah kelas CSS `<h1>` ke `"night"` dari tengah malam hingga pukul enam pagi dan `"day"` di waktu lain. Namun, ini tidak bekerja. Apakah Anda bisa memperbaiki jam ini?
235235

236-
You can verify whether your solution works by temporarily changing the computer's timezone. When the current time is between midnight and six in the morning, the clock should have inverted colors!
236+
Anda bisa memverifikasi solusi Anda dengan mengubah zona waktu komputer Anda. Saat waktu ada di antara tengah malam dan pukul enam pagi, warna jam berubah!
237237

238238
<Hint>
239239

240-
Rendering is a *calculation*, it shouldn't try to "do" things. Can you express the same idea differently?
240+
*Render* adalah *kalkulasi*. Oleh karena itu, seharusnya *render* tidak berusaha untuk "mengubah" sesuatu. Apakah Anda bisa mengekpresikan ide yang sama dengan cara yang berbeda?
241241

242242
</Hint>
243243

@@ -301,7 +301,7 @@ body > * {
301301

302302
<Solution>
303303

304-
You can fix this component by calculating the `className` and including it in the render output:
304+
Anda bisa memperbaiki komponen ini dengan mengalkulasi `className` dan menyertakannya di luaran *render*:
305305

306306
<Sandpack>
307307

@@ -362,19 +362,19 @@ body > * {
362362

363363
</Sandpack>
364364

365-
In this example, the side effect (modifying the DOM) was not necessary at all. You only needed to return JSX.
365+
Di contoh ini, efek samping (memodifikasi DOM) tidak perlu dilakukan. Anda hanya perlu mengembalikan JSX.
366366

367367
</Solution>
368368

369-
#### Fix a broken profile {/*fix-a-broken-profile*/}
369+
#### Memperbaiki profil rusak {/*fix-a-broken-profile*/}
370370

371-
Two `Profile` components are rendered side by side with different data. Press "Collapse" on the first profile, and then "Expand" it. You'll notice that both profiles now show the same person. This is a bug.
371+
Dua komponen `Profile` di-*render* secara berdampingan dengan data yang berbeda. Anda bisa menekan "*Collapse*" di profil pertama dan menekan "*Expand*". Anda akan melihat kedua profil menampilkan orang yang sama. Ini adalah sebuah *bug*.
372372

373-
Find the cause of the bug and fix it.
373+
Anda diminta untuk menemukan *bug* tersebut dan memperbaikinya.
374374

375375
<Hint>
376376

377-
The buggy code is in `Profile.js`. Make sure you read it all from top to bottom!
377+
Kode yang bermasalah ada di `Profile.js`. Pastikan Anda membaca seluruh kode tersebut!
378378

379379
</Hint>
380380

@@ -475,9 +475,9 @@ h1 { margin: 5px; font-size: 18px; }
475475

476476
<Solution>
477477

478-
The problem is that the `Profile` component writes to a preexisting variable called `currentPerson`, and the `Header` and `Avatar` components read from it. This makes *all three of them* impure and difficult to predict.
478+
Masalahnya adalah komponen `Profile` menulis ke variabel yang sudah ada sebelumnya, yaitu `currentPerson`, dan komponen `Header`, serta `Avatar` membaca variabel tersebut. Ini mengakibatkan *tiga komponen ini* tidak murni dan sulit untuk diprediksi.
479479

480-
To fix the bug, remove the `currentPerson` variable. Instead, pass all information from `Profile` to `Header` and `Avatar` via props. You'll need to add a `person` prop to both components and pass it all the way down.
480+
Untuk memperbaikinya, hapus variabel `currentPerson`. Justru, serahkan semua informasi dari `Profile` ke `Header` dan `Avatar` melalui *prop*. Anda perlu menambahkan *prop* `person` ke dua komponen tersebut dan meneruskan informasi tersebut.
481481

482482
<Sandpack>
483483

@@ -571,15 +571,15 @@ h1 { margin: 5px; font-size: 18px; }
571571

572572
</Sandpack>
573573

574-
Remember that React does not guarantee that component functions will execute in any particular order, so you can't communicate between them by setting variables. All communication must happen through props.
574+
Anda harus ingat React tidak menjamin sebuah fungsi komponen akan dieksekusi berdasarkan suatu urutan sehingga Anda tidak bisa membangun komunikasi antarkomponen dengan menggunakan variabel. Smeua komunikasi harus dilakukan melalui *prop*.
575575

576576
</Solution>
577577

578-
#### Fix a broken story tray {/*fix-a-broken-story-tray*/}
578+
#### Memperbaiki *story tray* rusak {/*fix-a-broken-story-tray*/}
579579

580-
The CEO of your company is asking you to add "stories" to your online clock app, and you can't say no. You've written a `StoryTray` component that accepts a list of `stories`, followed by a "Create Story" placeholder.
580+
*CEO* perusahaan Anda meminta Anda untuk menambahkan "*story*" ke aplikasi jam daring Anda dan Anda tidak bisa menolak permintaan tersebut. Anda telah menulis sebuah komponen `StoryTray` yang menerima daftar berisikan `stories`, kemudian diikuti *placeholder* "*Create Story*".
581581

582-
You implemented the "Create Story" placeholder by pushing one more fake story at the end of the `stories` array that you receive as a prop. But for some reason, "Create Story" appears more than once. Fix the issue.
582+
Anda telah mengimplementasi *placeholder* "*Create Story*" dengan menambahkan satu *story* palsu di akhir senarai `stories` yang Anda terima sebagai `prop`. Sayangnya, entah mengapa, "*Create Story*" muncul lebih dari satu kali. Anda diminta untuk memperbaiki ini.
583583

584584
<Sandpack>
585585

@@ -675,11 +675,11 @@ li {
675675

676676
<Solution>
677677

678-
Notice how whenever the clock updates, "Create Story" is added *twice*. This serves as a hint that we have a mutation during rendering--Strict Mode calls components twice to make these issues more noticeable.
678+
Perhatikan bagaimana saat jam berubah, "*Create Story*" ditambahkan *dua kali*. Ini mengindikasikan komponen melakukan mutasi pada saat me-*render*--*Strict Mode* memanggil komponen dua kali untuk menunjukkan masalah ini.
679679

680-
`StoryTray` function is not pure. By calling `push` on the received `stories` array (a prop!), it is mutating an object that was created *before* `StoryTray` started rendering. This makes it buggy and very difficult to predict.
680+
Fungsi `StoryTray` tidak murni. Dengan memanggil `push` kepada senarai `stories` yang diterima (sebuah *prop*!), fungsi ini memutasi sebuah objek yang dibuat *sebelum* `StoryTray` mulai me-*render*. Ini yang mengakibatkan *bug* dan komponen menjadi sulit diprediksi.
681681

682-
The simplest fix is to not touch the array at all, and render "Create Story" separately:
682+
Solusi paling sederhana adalah untuk tidak menyentuh senarai dan me-*render* "*Create Story*" secara terpisah:
683683

684684
<Sandpack>
685685

@@ -763,16 +763,16 @@ li {
763763

764764
</Sandpack>
765765

766-
Alternatively, you could create a _new_ array (by copying the existing one) before you push an item into it:
766+
Solusi alternatif adalah Anda bisa membuat sebuah senarai *baru* (dengan menyalin senarai yang sudah ada) sebelum Anda menambahkan anggota baru ke dalamnya:
767767

768768
<Sandpack>
769769

770770
```js StoryTray.js active
771771
export default function StoryTray({ stories }) {
772-
// Copy the array!
772+
// Salin senarai!
773773
let storiesToDisplay = stories.slice();
774774

775-
// Does not affect the original array:
775+
// Tidak mengubah senarai asli:
776776
storiesToDisplay.push({
777777
id: 'create',
778778
label: 'Create Story'
@@ -855,9 +855,9 @@ li {
855855

856856
</Sandpack>
857857

858-
This keeps your mutation local and your rendering function pure. However, you still need to be careful: for example, if you tried to change any of the array's existing items, you'd have to clone those items too.
858+
Ini menjaga mutasi Anda tetap lokal dan proses *render* tetap murni. Namun, Anda tetap harus berhati-hati: misalnya, jika Anda berusaha untuk mengubah anggota dari senarai tersebut, Anda harus menyalin anggota tersebut terlebih dahulu sebelum mengubahnya.
859859

860-
It is useful to remember which operations on arrays mutate them, and which don't. For example, `push`, `pop`, `reverse`, and `sort` will mutate the original array, but `slice`, `filter`, and `map` will create a new one.
860+
Oleh karena itu, sangat penting bagi Anda untuk mengingat operasi yang memutasi senarai dan yang tidak. Misalnya, `push`, `pop`, `reverse`, dan `sort` memutasi senarai asli, tetapi `slice`, `filter`, dan `map` akan membuat senarai baru.
861861

862862
</Solution>
863863

0 commit comments

Comments
 (0)