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/describing-the-ui.md
+76-76
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,29 @@
1
1
---
2
-
title: Describing the UI
2
+
title: Menggambarkan Antarmuka Pengguna (UI)
3
3
---
4
4
5
5
<Intro>
6
6
7
-
React is a JavaScript library for rendering user interfaces (UI). UI is built from small units like buttons, text, and images. React lets you combine them into reusable, nestable *components.* From web sites to phone apps, everything on the screen can be broken down into components. In this chapter, you'll learn to create, customize, and conditionally display React components.
7
+
React adalah pustaka JavaScript untuk melakukan *render* antarmuka pengguna (*User Interface* - UI). UI dibangun dari unit-unit kecil seperti tombol, teks, dan gambar. React memungkinkan Anda menggabungkan unit-unit tersebut menjadi suatu komponen yang *reusable* (dapat digunakan kembali), dan *nestable* (dapat diletakkan secara bersarang dan/atau di bawah komponen lainnya). Dari situs web hingga aplikasi, semua yang ada pada layar dapat dipecah menjadi komponen. Dalam bab ini, Anda akan belajar membuat, menyesuaikan, dan menampilkan komponen React secara kondisional.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearnisChapter={true}>
12
12
13
-
*[How to write your first React component](/learn/your-first-component)
14
-
*[When and how to create multi-component files](/learn/importing-and-exporting-components)
15
-
*[How to add markup to JavaScript with JSX](/learn/writing-markup-with-jsx)
16
-
*[How to use curly braces with JSX to access JavaScript functionality from your components](/learn/javascript-in-jsx-with-curly-braces)
17
-
*[How to configure components with props](/learn/passing-props-to-a-component)
18
-
*[How to conditionally render components](/learn/conditional-rendering)
19
-
*[How to render multiple components at a time](/learn/rendering-lists)
20
-
*[How to avoid confusing bugs by keeping components pure](/learn/keeping-components-pure)
13
+
*[Cara menulis komponen React pertama Anda](/learn/your-first-component)
14
+
*[Kapan dan bagaimana membuat file multi-komponen](/learn/importing-and-exporting-components)
15
+
*[Cara menambahkan markup ke JavaScript dengan JSX](/learn/writing-markup-with-jsx)
16
+
*[Cara menggunakan kurung kurawal dengan JSX untuk mengakses fungsionalitas JavaScript dari komponen Anda](/learn/javascript-in-jsx-with-curly-braces)
17
+
*[Cara mengonfigurasi komponen dengan props](/learn/passing-props-to-a-component)
18
+
*[Cara melakukan render komponen secara kondisional](/learn/conditional-rendering)
19
+
*[Cara melakukan render beberapa komponen sekaligus](/learn/rendering-lists)
20
+
*[Cara menghindari bug yang membingungkan dengan menjaga komponen tetap murni](/learn/keeping-components-pure)
21
21
22
22
</YouWillLearn>
23
23
24
-
## Your first component {/*your-first-component*/}
24
+
## Komponen Pertama Anda {/*your-first-component*/}
25
25
26
-
React applications are built from isolated pieces of UI called *components*. A React component is a JavaScript function that you can sprinkle with markup. Components can be as small as a button, or as large as an entire page. Here is a `Gallery`component rendering three `Profile` components:
26
+
Aplikasi React dibangun dari potongan-potongan antarmuka pengguna (UI) yang terisolasi yang disebut *komponen*. Komponen React adalah sebuah fungsi JavaScript yang dapat Anda tambahkan dengan *markup*. Komponen dapat sekecil tombol atau sebesar halaman utuh. Berikut adalah contoh komponen `Gallery`yang me-*render* tiga komponen `Profile`:
Read**[Your First Component](/learn/your-first-component)**to learn how to declare and use React components.
60
+
Baca**[Komponen Pertama Anda](/learn/your-first-component)**untuk mempelajari cara mendeklarasikan dan menggunakan komponen React.
61
61
62
62
</LearnMore>
63
63
64
-
## Importing and exporting components {/*importing-and-exporting-components*/}
64
+
## Mengimpor dan Mengekspor Komponen {/*importing-and-exporting-components*/}
65
65
66
-
You can declare many components in one file, but large files can get difficult to navigate. To solve this, you can *export* a component into its own file, and then *import* that component from another file:
66
+
Anda dapat mendeklarasikan banyak komponen dalam satu file, tetapi file yang besar dapat menjadi sulit untuk dinavigasi/dibaca. Untuk memecahkan masalah ini, Anda dapat *mengekspor* sebuah komponen ke dalam file sendiri, dan kemudian *mengimpor* komponen tersebut dari file lain:
67
67
68
68
69
69
<Sandpack>
@@ -84,7 +84,7 @@ import Profile from './Profile.js';
Read**[Importing and Exporting Components](/learn/importing-and-exporting-components)**to learn how to split components into their own files.
115
+
Baca**[Mengimpor dan Mengekspor Komponen](/learn/importing-and-exporting-components)** untuk belajar bagaimana memecah komponen ke dalam file-file terpisah.
116
116
117
117
</LearnMore>
118
118
119
-
## Writing markup with JSX {/*writing-markup-with-jsx*/}
119
+
## Menulis markup dengan JSX {/*writing-markup-with-jsx*/}
120
120
121
-
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information.
121
+
Setiap komponen React adalah sebuah fungsi JavaScript yang dapat berisi beberapa *markup* yang di-*render* oleh React ke peramban. Komponen React menggunakan ekstensi sintaksis bernama JSX untuk merepresentasikan *markup* tersebut. JSX terlihat mirip dengan HTML, tetapi sedikit lebih ketat dan dapat menampilkan informasi yang dinamis.
122
122
123
-
If we paste existing HTML markup into a React component, it won't always work:
123
+
Menempel *markup*HTML ke dalam komponen React tidak selalu akan berfungsi:
124
124
125
125
<Sandpack>
126
126
127
127
```js
128
128
exportdefaultfunctionTodoList() {
129
129
return (
130
-
//This doesn't quite work!
130
+
//Ini tidak cukup berhasil
131
131
<h1>Hedy Lamarr's Todos</h1>
132
132
<img
133
133
src="https://i.imgur.com/yXOvdOSs.jpg"
134
134
alt="Hedy Lamarr"
135
135
class="photo"
136
136
>
137
137
<ul>
138
-
<li>Invent new traffic lights
139
-
<li>Rehearse a movie scene
140
-
<li>Improve spectrum technology
138
+
<li>Ciptakan lampu lalu lintas baru
139
+
<li>Latih adegan film
140
+
<li>Meningkatkan teknologi spektrum
141
141
</ul>
142
142
);
143
143
}
@@ -149,7 +149,7 @@ img { height: 90px; }
149
149
150
150
</Sandpack>
151
151
152
-
If you have existing HTML like this, you can fix it using a [converter](https://transform.tools/html-to-jsx):
152
+
Jika Anda memiliki HTML seperti ini, Anda dapat memperbaikinya menggunakan [konverter](https://transform.tools/html-to-jsx):
153
153
154
154
<Sandpack>
155
155
@@ -164,9 +164,9 @@ export default function TodoList() {
164
164
className="photo"
165
165
/>
166
166
<ul>
167
-
<li>Invent newtraffic lights</li>
168
-
<li>Rehearse a movie scene</li>
169
-
<li>Improve spectrum technology</li>
167
+
<li>Ciptakan lampu lalu lintas baru</li>
168
+
<li>Latih adegan film</li>
169
+
<li>Meningkatkan teknologi spektrum</li>
170
170
</ul>
171
171
</>
172
172
);
@@ -181,13 +181,13 @@ img { height: 90px; }
181
181
182
182
<LearnMorepath="/learn/writing-markup-with-jsx">
183
183
184
-
Read**[Writing Markup with JSX](/learn/writing-markup-with-jsx)**to learn how to write valid JSX.
184
+
Baca**[Menulis Markup dengan JSX](/learn/writing-markup-with-jsx)**untuk mempelajarai cara menulis JSX yang valid.
185
185
186
186
</LearnMore>
187
187
188
-
## JavaScript in JSX with curly braces {/*javascript-in-jsx-with-curly-braces*/}
188
+
## JavaScript di dalam JSX dengan kurung kurawal {/*javascript-in-jsx-with-curly-braces*/}
189
189
190
-
JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to "open a window" to JavaScript:
190
+
JSX memungkinkan Anda menulis *markup* mirip HTML di dalam file JavaScript, menjaga logika *rendering* dan konten di tempat yang sama. Terkadang Anda ingin menambahkan sedikit logika JavaScript atau merujuk pada properti dinamis di dalam markup tersebut. Dalam situasi ini, Anda dapat menggunakan kurung kurawal di JSX Anda untuk "membuka jendela" ke JavaScript:
191
191
192
192
<Sandpack>
193
193
@@ -210,9 +210,9 @@ export default function TodoList() {
210
210
alt="Gregorio Y. Zara"
211
211
/>
212
212
<ul>
213
-
<li>Improve the videophone</li>
214
-
<li>Prepare aeronautics lectures</li>
215
-
<li>Work on the alcohol-fuelled engine</li>
213
+
<li>Meningkatkan videophone</li>
214
+
<li>Menyiapkan kuliah aeronautika</li>
215
+
<li>Mengerjakan mesin berbahan bakar alkohol</li>
216
216
</ul>
217
217
</div>
218
218
);
@@ -229,13 +229,13 @@ body > div > div { padding: 20px; }
Read **[JavaScript in JSX with Curly Braces](/learn/javascript-in-jsx-with-curly-braces)** to learn how to access JavaScript data from JSX.
232
+
Baca **[JavaScript di dalam JSX dengan Kurung Kurawal](/learn/javascript-in-jsx-with-curly-braces)** untuk mempelajari cara mengakses data JavaScript dari JSX.
233
233
234
234
</LearnMore>
235
235
236
-
## Passing props to a component {/*passing-props-to-a-component*/}
236
+
## Mengoper Props ke sebuah Komponen {/*passing-props-to-a-component*/}
237
237
238
-
React components use *props* to communicate with each other. Every parent component can pass some information to its child components by giving them props. Props might remind you of HTML attributes, but you can pass any JavaScript value through them, including objects, arrays, functions, and even JSX!
238
+
Komponen React menggunakan *props* untuk berkomunikasi satu sama lain. Setiap komponen induk dapat memberikan informasi ke komponen anaknya dengan memberikan *props*. *Props* mungkin mengingatkan Anda pada atribut HTML, tetapi Anda dapat mengoper nilai JavaScript apa pun melalui *props*, termasuk objek, senarai, fungsi, dan bahkan JSX!
## Merender Secara Kondisional {/*conditional-rendering*/}
318
318
319
-
Your components will often need to display different things depending on different conditions. In React, you can conditionally render JSX using JavaScript syntax like `if` statements, `&&`, and`?:`operators.
319
+
Komponen Anda seringkali perlu menampilkan hal-hal yang berbeda tergantung pada kondisi yang berbeda. Di React, Anda dapat me-*render* JSX secara kondisional menggunakan sintaks JavaScript seperti `if`*statements*, `&&`, dan`?:`operator.
320
320
321
-
In this example, the JavaScript `&&`operator is used to conditionally render a checkmark:
321
+
Dalam contoh ini, operator `&&`JavaScript digunakan untuk me-*render* centang secara kondisional:
322
322
323
323
<Sandpack>
324
324
@@ -334,19 +334,19 @@ function Item({ name, isPacked }) {
334
334
exportdefaultfunctionPackingList() {
335
335
return (
336
336
<section>
337
-
<h1>Sally Ride's Packing List</h1>
337
+
<h1>Daftar Perlengkapan Sally Ride</h1>
338
338
<ul>
339
339
<Item
340
340
isPacked={true}
341
-
name="Space suit"
341
+
name="Pakaian luar angkasa"
342
342
/>
343
343
<Item
344
344
isPacked={true}
345
-
name="Helmet with a golden leaf"
345
+
name="Helm dengan daun emas"
346
346
/>
347
347
<Item
348
348
isPacked={false}
349
-
name="Photo of Tam"
349
+
name="Foto Tam"
350
350
/>
351
351
</ul>
352
352
</section>
@@ -358,15 +358,15 @@ export default function PackingList() {
358
358
359
359
<LearnMorepath="/learn/conditional-rendering">
360
360
361
-
Read **[Conditional Rendering](/learn/conditional-rendering)** to learn the different ways to render content conditionally.
361
+
Baca**[Merender Secara Kondisional](/learn/conditional-rendering)**untuk mempelajari cara merender konten secara kondisional.
362
362
363
363
</LearnMore>
364
364
365
-
## Rendering lists {/*rendering-lists*/}
365
+
## Merender List {/*rendering-lists*/}
366
366
367
-
You will often want to display multiple similar components from a collection of data. You can use JavaScript's `filter()`and`map()`with React to filter and transform your array of data into an array of components.
367
+
Anda akan sering ingin menampilkan beberapa komponen serupa dari koleksi data. Anda dapat menggunakan `filter()`dan`map()`dari JavaScript dengan React untuk menyaring dan mentransformasikan senarai data Anda menjadi senarai komponen.
368
368
369
-
For each array item, you will need to specify a `key`. Usually, you will want to use an IDfrom the database as a `key`. Keyslet React keep track of each item's place in the list even if the list changes.
369
+
Untuk setiap *item* pada senarai, Anda perlu menentukan sebuah kunci `key`. Biasanya, Anda ingin menggunakan ID dari basisdata sebagai `key`. `key` memungkinkan React untuk melacak posisi setiap *item* di dalam daftar bahkan jika daftar berubah.
370
370
371
371
<Sandpack>
372
372
@@ -384,13 +384,13 @@ export default function List() {
384
384
<p>
385
385
<b>{person.name}:</b>
386
386
{''+person.profession+''}
387
-
known for {person.accomplishment}
387
+
yang terkenal dengan {person.accomplishment}
388
388
</p>
389
389
</li>
390
390
);
391
391
return (
392
392
<article>
393
-
<h1>Scientists</h1>
393
+
<h1>Ilmuwan</h1>
394
394
<ul>{listItems}</ul>
395
395
</article>
396
396
);
@@ -401,32 +401,32 @@ export default function List() {
401
401
exportconstpeople= [{
402
402
id:0,
403
403
name:'Creola Katherine Johnson',
404
-
profession: 'mathematician',
405
-
accomplishment: 'spaceflight calculations',
404
+
profession:'ahli matematika',
405
+
accomplishment:'perhitungan penerbangan luar angkasa',
406
406
imageId:'MK3eW3A'
407
407
}, {
408
408
id:1,
409
409
name:'Mario José Molina-Pasquel Henríquez',
410
-
profession: 'chemist',
411
-
accomplishment: 'discovery of Arctic ozone hole',
410
+
profession:'ahli kimia',
411
+
accomplishment:'penemuan lubang ozon Arktik',
412
412
imageId:'mynHUSa'
413
413
}, {
414
414
id:2,
415
415
name:'Mohammad Abdus Salam',
416
-
profession: 'physicist',
417
-
accomplishment: 'electromagnetism theory',
416
+
profession:'ahli fisika',
417
+
accomplishment:'teori elektromagnetik',
418
418
imageId:'bE7W1ji'
419
419
}, {
420
420
id:3,
421
421
name:'Percy Lavon Julian',
422
-
profession: 'chemist',
423
-
accomplishment: 'pioneering cortisone drugs, steroids and birth control pills',
422
+
profession:'ahli kimia',
423
+
accomplishment:'perintis obat kortison, steroid dan pil KB',
424
424
imageId:'IOjWm71'
425
425
}, {
426
426
id:4,
427
427
name:'Subrahmanyan Chandrasekhar',
428
-
profession: 'astrophysicist',
429
-
accomplishment: 'white dwarf star mass calculations',
428
+
profession:'ahli astrofisika',
429
+
accomplishment:'perhitungan massa bintang kerdil putih',
430
430
imageId:'lrWQx8l'
431
431
}];
432
432
```
@@ -458,28 +458,28 @@ h2 { font-size: 20px; }
458
458
459
459
<LearnMorepath="/learn/rendering-lists">
460
460
461
-
Read**[Rendering Lists](/learn/rendering-lists)**to learn how to render a list of components, and how to choose a key.
461
+
Baca**[Merender List](/learn/rendering-lists)**untuk mempelajari cara me-*render* daftar komponen dan cara memilih `key`.
462
462
463
463
</LearnMore>
464
464
465
-
## Keeping components pure {/*keeping-components-pure*/}
465
+
## Menjaga Komponen Tetap Murni {/*keeping-components-pure*/}
466
466
467
-
Some JavaScript functions are *pure.* A pure function:
467
+
Sebagian fungsi JavaScript adalah murni (*pure*). Sebuah fungsi murni:
468
468
469
-
***Minds its own business.**It does not change any objects or variables that existed before it was called.
470
-
***Same inputs, same output.**Given the same inputs, a pure function should always return the same result.
469
+
***Memperhatikan urusannya sendiri.**fungsi tidak mengubah objek atau variabel apapun yang ada sebelum fungsi dipanggil.
470
+
***_Input_ sama, _output_ sama.** Dengan *input* yang sama, sebuah fungsi murni harus selalu memiliki *output* yang sama.
471
471
472
-
By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. Here is an example of an impure component:
472
+
Dengan hanya benar-benar menulis komponen Anda sebagai fungsi murni, Anda dapat menghindari seluruh *bug* yang membingungkan dan perilaku yang tidak dapat diprediksi saat kode Anda berkembang. Berikut ini adalah contoh komponen tidak murni:
473
473
474
474
<Sandpack>
475
475
476
476
```js
477
477
let guest =0;
478
478
479
479
functionCup() {
480
-
//Bad: changing a preexisting variable!
480
+
//Buruk: memodifikasi variabel yang sudah ada sebelum Cup dipanggil!
481
481
guest = guest +1;
482
-
return<h2>Tea cup for guest #{guest}</h2>;
482
+
return<h2>Cangkir teh untuk tamu #{guest}</h2>;
483
483
}
484
484
485
485
exportdefaultfunctionTeaSet() {
@@ -495,13 +495,13 @@ export default function TeaSet() {
495
495
496
496
</Sandpack>
497
497
498
-
You can make this component pure by passing a prop instead of modifying a preexisting variable:
498
+
Anda dapat membuat komponen ini menjadi murni dengan mengoper sebuah *prop* daripada memodifikasi variabel yang sudah ada:
499
499
500
500
<Sandpack>
501
501
502
502
```js
503
503
functionCup({ guest }) {
504
-
return<h2>Tea cup for guest #{guest}</h2>;
504
+
return<h2>Cangkir teh untuk tamu #{guest}</h2>;
505
505
}
506
506
507
507
exportdefaultfunctionTeaSet() {
@@ -519,12 +519,12 @@ export default function TeaSet() {
519
519
520
520
<LearnMorepath="/learn/keeping-components-pure">
521
521
522
-
Read**[Keeping Components Pure](/learn/keeping-components-pure)**to learn how to write components as pure, predictable functions.
522
+
Baca**[Menjaga Komponen Tetap Murni](/learn/keeping-components-pure)**untuk mempelajari cara menulis komponen sebagai fungsi yang murni dan dapat diprediksi.
523
523
524
524
</LearnMore>
525
525
526
-
## What's next? {/*whats-next*/}
526
+
## Apa selanjutnya? {/*whats-next*/}
527
527
528
-
Head over to [Your First Component](/learn/your-first-component)to start reading this chapter page by page!
528
+
Lanjut ke [Komponen Pertama Anda](/learn/your-first-component)untuk mulai membaca halaman bab ini dari awal!
529
529
530
-
Or, if you're already familiar with these topics, why not read about [Adding Interactivity](/learn/adding-interactivity)?
530
+
Atau, jika Anda sudah familiar dengan topik ini, mengapa tidak membaca tentang [Menambahkan Interaktivitas](/learn/adding-interactivity)?
0 commit comments