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
This funny tag syntax is neither a string nor HTML.
15
+
Sintaks *tag* aneh ini bukanlah sebuah *string* ataupun *HTML*.
16
16
17
-
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript.
17
+
Sintaks ini di kenal dengan sebutan JSX, dan sintaks ini adalah sebuah sintaks ekstensi untuk *JavaScript*. Kami sarankan menggunakannya dengan React untuk mendeskripsikan bagimana antarmuka pengguna seharusnya terlihat. JSX mungkin akan mengingatkan anda dengan sebuah bahasa *templat*, bedanya adalah JSX telah dilengkapi dengan kekuatan penuh dari JavaScript.
18
18
19
-
JSX produces React "elements". We will explore rendering them to the DOM in the [next section](/docs/rendering-elements.html). Below, you can find the basics of JSX necessary to get you started.
19
+
JSX akan menghasilkan "elemen" React. Kita akan mulai mengeksplor bagaimana me-*render* mereka ke dalam DOM di bagian [berikutnya](/docs/rendering-elements.html). Di bawah ini, anda akan menemukan dasar-dasar JSX yang anda butuhkan untuk memulai.
20
20
21
-
### Why JSX? {#why-jsx}
21
+
### Mengapa JSX? {#why-jsx}
22
22
23
-
React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time, and how the data is prepared for display.
23
+
React mengakui bahwa logika *rendering* akan secara inheren digabungkan dengan logika antarmuka pengguna lainnya. bagaimana *events* akan ditangani, bagaimana *state* berubah seiring dengan waktu, dan bagaimana data disiapkan untuk di tampilkan.
24
24
25
-
Instead of artificially separating *technologies*by putting markup and logic in separate files, React [separates *concerns*](https://en.wikipedia.org/wiki/Separation_of_concerns)with loosely coupled units called "components" that contain both. We will come back to components in a [further section](/docs/components-and-props.html), but if you're not yet comfortable putting markup in JS, [this talk](https://www.youtube.com/watch?v=x7cQ3mrcKaY)might convince you otherwise.
25
+
Alih-alih memisahkan *technologies*secara artifisial dengan meletakkan *markup* dan logika di file terpisah, React [memisahkan kepentingan *(separates concerns)*](https://en.wikipedia.org/wiki/Separation_of_concerns)dengan unit kopling rendah bernama "komponen" yang mengandung keduanya. Kita akan kembali ke komponen dalam [bagian selanjutnya](/docs/components-and-props.html), tetapi jika anda merasa belum nyaman menempatkan *markup* di `JavaScript`, [video ini](https://www.youtube.com/watch?v=x7cQ3mrcKaY)mungkin akan meyakinkan anda.
26
26
27
-
React [doesn't require](/docs/react-without-jsx.html)using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.
27
+
React [tidak mengharuskan](/docs/react-without-jsx.html)anda untuk menggunakan JSX, namun kebanyakan orang merasa terbantu dengan adanya JSX sebagai bantuan visual saat mengerjakan antarmuka pengguna di dalam kode *JavaScript*. Menggunakan JSX juga memungkinkan React untuk menampilkan pesan kesalahan *(error)* dan peringatan *(warning)* yang lebih bermanfaat.
28
28
29
-
With that out of the way, let's get started!
29
+
Setelah anda memahaminya, mari kita mulai!
30
30
31
-
### Embedding Expressions in JSX {#embedding-expressions-in-jsx}
31
+
### Menyematkan Ekspresi di JSX {#embedding-expressions-in-jsx}
32
32
33
-
In the example below, we declare a variable called `name`and then use it inside JSX by wrapping it in curly braces:
33
+
Dalam contoh di bawah ini, kita mendeklarasikan variabel bernama `name`dan kemudian menggunakannya di dalam JSX dengan cara membungkusnya di dalam tanda kurung kurawal *(curly braces)*:
34
34
35
35
```js{1,2}
36
-
const name = 'Josh Perez';
37
-
const element = <h1>Hello, {name}</h1>;
36
+
const name = 'Budi';
37
+
const element = <h1>Halo, {name}</h1>;
38
38
39
39
ReactDOM.render(
40
40
element,
41
41
document.getElementById('root')
42
42
);
43
43
```
44
44
45
-
You can put any valid [JavaScript expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions)inside the curly braces in JSX. For example, `2 + 2`, `user.firstName`, or`formatName(user)`are all valid JavaScript expressions.
45
+
Anda dapat menyematkan semua [ekspresi *JavaScript*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions)yang valid di dalam tanda kurung kurawal di JSX. Sebagai contoh, `2 + 2`, `user.firstName`, atau`formatName(user)`adalah ekspresi JavaScript yang valid.
46
46
47
-
In the example below, we embed the result of calling a JavaScript function, `formatName(user)`, into an`<h1>` element.
47
+
Pada contoh di bawah ini, kami menyematkan hasil memanggil fungsi JavaScript, `formatName(user)`, kedalam elemen`<h1>`.
48
48
49
49
```js{12}
50
50
function formatName(user) {
51
51
return user.firstName + ' ' + user.lastName;
52
52
}
53
53
54
54
const user = {
55
-
firstName: 'Harper',
56
-
lastName: 'Perez'
55
+
firstName: 'Budi',
56
+
lastName: 'Mahardika'
57
57
};
58
58
59
59
const element = (
60
60
<h1>
61
-
Hello, {formatName(user)}!
61
+
Halo, {formatName(user)}!
62
62
</h1>
63
63
);
64
64
@@ -68,88 +68,88 @@ ReactDOM.render(
68
68
);
69
69
```
70
70
71
-
[](codepen://introducing-jsx)
71
+
[Coba di CodePen](codepen://introducing-jsx)
72
72
73
-
We split JSX over multiple lines for readability. While it isn't required, when doing this, we also recommend wrapping it in parentheses to avoid the pitfalls of [automatic semicolon insertion](http://stackoverflow.com/q/2846283).
73
+
Kami membagi JSX menjadi beberapa baris agar mudah dibaca. Meskipun tidak diwajibkan, ketika melakukan hal ini, kami juga merekomendasikan anda membungkusnya dalam tanda kurung untuk menghindari terjadinya [penyisipan titik koma otomatis](http://stackoverflow.com/q/2846283).
74
74
75
-
### JSX is an Expression Too {#jsx-is-an-expression-too}
75
+
### JSX adalah Ekspresi Juga {#jsx-is-an-expression-too}
76
76
77
-
After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.
77
+
Setelah dikompilasi, Ekspresi JSX akan menjadi panggilan fungsi JavaScript biasa dan menjadi objek JavaScript.
78
78
79
-
This means that you can use JSX inside of `if`statements and`for` loops, assign it to variables, accept it as arguments, and return it from functions:
79
+
Hal ini berarti bahwa Anda dapat menggunakan JSX di dalam pernyataan `if`dan perulangan`for`, memasukkannya ke dalam variabel, menerimanya sebagai argumen, dan mengembalikannya dari sebuah fungsi:
80
80
81
81
```js{3,5}
82
82
function getGreeting(user) {
83
83
if (user) {
84
-
return <h1>Hello, {formatName(user)}!</h1>;
84
+
return <h1>Halo, {formatName(user)}!</h1>;
85
85
}
86
-
return <h1>Hello, Stranger.</h1>;
86
+
return <h1>Halo, Orang Asing.</h1>;
87
87
}
88
88
```
89
89
90
-
### Specifying Attributes with JSX {#specifying-attributes-with-jsx}
90
+
### Menentukan Atribut dengan JSX {#specifying-attributes-with-jsx}
91
91
92
-
You may use quotes to specify string literals as attributes:
92
+
Anda dapat menggunakan tanda kutip untuk menentukan *string* literal sebagai atribut:
93
93
94
94
```js
95
95
constelement=<div tabIndex="0"></div>;
96
96
```
97
97
98
-
You may also use curly braces to embed a JavaScript expression in an attribute:
98
+
Anda juga dapat menggunakan kurung kurawal untuk menyematkan ekspresi JavaScript di dalam atribut:
99
99
100
100
```js
101
101
constelement=<img src={user.avatarUrl}></img>;
102
102
```
103
103
104
-
Don't put quotes around curly braces when embedding a JavaScript expression in an attribute. You should either use quotes (for string values) or curly braces (for expressions), but not both in the same attribute.
104
+
Jangan letakan tanda kutip di sekitar kurung kurawal saat menyematkan ekspresi JavaScript di dalam atribut. Anda bisa menggunakan tanda kutip (untuk nilai string) atau kurung kurawal (untuk ekspresi), tetapi jangan menggunakan keduanya dalam atribut yang sama.
105
105
106
-
>**Warning:**
106
+
>**Peringatan:**
107
107
>
108
-
>Since JSX is closer to JavaScript than to HTML, React DOM uses`camelCase`property naming convention instead of HTML attribute names.
108
+
>Karena JSX lebih dekat ke JavaScript daripada ke HTML, React DOM menggunakan`camelCase`sebagai konvensi penamaan alih-alih menggunakan konvensi penamaan atribut HTML.
109
109
>
110
-
>For example, `class`becomes [`className`](https://developer.mozilla.org/en-US/docs/Web/API/Element/className)in JSX, and`tabindex`becomes[`tabIndex`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex).
110
+
>Sebagai contoh, `class`akan menjadi [`className`](https://developer.mozilla.org/en-US/docs/Web/API/Element/className)di JSX, dan`tabindex`akan menjadi[`tabIndex`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex).
111
111
112
-
### Specifying Children with JSX {#specifying-children-with-jsx}
112
+
### Menspesifikasikan Elemen Anak dengan JSX {#specifying-children-with-jsx}
113
113
114
-
If a tag is empty, you may close it immediately with `/>`, like XML:
114
+
Jika *tag* bersifat kosong (tidak memiliki elemen anak), anda bisa saja menutupnya secara langsung dengan `/>`, seperti XML:
### JSX Mencegah Serangan Injeksi {#jsx-prevents-injection-attacks}
132
132
133
-
It is safe to embed user input in JSX:
133
+
Anda dapat menanamkan input pengguna di JSX dengan aman:
134
134
135
135
```js
136
136
consttitle=response.potentiallyMaliciousInput;
137
-
//This is safe:
137
+
//Ini aman:
138
138
constelement=<h1>{title}</h1>;
139
139
```
140
140
141
-
By default, React DOM [escapes](http://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-on-html)any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that's not explicitly written in your application. Everything is converted to a string before being rendered. This helps prevent [XSS (cross-site-scripting)](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks.
141
+
Secara default, React DOM [meng-*escape*](http://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-on-html)nilai apapun yang ditaruh di dalam JSX sebelum me-*render* mereka. Oleh karena itu dapat dipastikan anda tidak akan pernah menginjeksi apapun yang tidak ditulis di aplikasi anda secara eksplisit. Semuanya akan diubah menjadi *string* sebelum di-*render*. Ini membantu mencegah ada nya serangan [XSS (skrip-lintas-situs)](https://en.wikipedia.org/wiki/Cross-site_scripting).
Babel compiles JSX down to`React.createElement()` calls.
145
+
Babel akan meng-*compile*JSX menjadi pemanggilan`React.createElement()`.
146
146
147
-
These two examples are identical:
147
+
Dua contoh ini akan menghasilkan hal yang sama:
148
148
149
149
```js
150
150
constelement= (
151
151
<h1 className="greeting">
152
-
Hello, world!
152
+
Halo, Dunia!
153
153
</h1>
154
154
);
155
155
```
@@ -158,27 +158,27 @@ const element = (
158
158
constelement=React.createElement(
159
159
'h1',
160
160
{className:'greeting'},
161
-
'Hello, world!'
161
+
'Halo, Dunia!'
162
162
);
163
163
```
164
164
165
-
`React.createElement()`performs a few checks to help you write bug-free code but essentially it creates an object like this:
165
+
`React.createElement()`melakukan serangkaian pengecekan yang membantu anda menulis kode yang bebas dari *bug* namun pada dasarnya akan membuat objek seperti ini:
166
166
167
167
```js
168
-
//Note: this structure is simplified
168
+
//Catatan: struktur ini sudah disederhanakan
169
169
constelement= {
170
170
type:'h1',
171
171
props: {
172
172
className:'greeting',
173
-
children:'Hello, world!'
173
+
children:'Halo, Dunia!'
174
174
}
175
175
};
176
176
```
177
177
178
-
These objects are called "React elements". You can think of them as descriptions of what you want to see on the screen. React reads these objects and uses them to construct the DOM and keep it up to date.
178
+
Objek seperti ini disebut "elemen React". Anda dapat menganggap mereka sebagai deskripsi dari apa yang anda ingin lihat di layar. React membaca objek-objek ini dan menggunakan mereka untuk membangun DOM dan membuatnya tetap sesuai dengan kondisi saat ini.
179
179
180
-
We will explore rendering React elements to the DOM in the next section.
180
+
Kita akan mengeksplorasi *rendering* pada elemen React ke DOM dalam bagian berikutnya.
181
181
182
-
>**Tip:**
182
+
>**Saran:**
183
183
>
184
-
>We recommend using the ["Babel" language definition](http://babeljs.io/docs/editors)for your editor of choice so that both ES6 and JSX code is properly highlighted. This website uses the [Oceanic Next](https://labs.voronianski.com/oceanic-next-color-scheme/)color scheme which is compatible with it.
184
+
>Kami merokemendasikan anda untuk mencari [skema sintaks "Babel"](http://babeljs.io/docs/editors)untuk editor pilihan anda sehingga baik kode ES6 dan JSX bisa di-*highlight* dengan benar. Situs web ini menggunakan skema warna [*Oceanic Next*](https://labs.voronianski.com/oceanic-next-color-scheme/)yang kompatibel dengannya.
0 commit comments