Skip to content

Commit 807c3a3

Browse files
authored
Translate Introducing JSX (#13)
* Translate introducing-jsx * Update typo * Translate code block
1 parent 73f04d0 commit 807c3a3

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

content/docs/introducing-jsx.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
---
22
id: introducing-jsx
3-
title: Introducing JSX
3+
title: Memperkenalkan JSX
44
permalink: docs/introducing-jsx.html
55
prev: hello-world.html
66
next: rendering-elements.html
77
---
88

9-
Consider this variable declaration:
9+
Cobalah lihat deklarasi variabel dibawah ini:
1010

1111
```js
12-
const element = <h1>Hello, world!</h1>;
12+
const element = <h1>Halo, Dunia!</h1>;
1313
```
1414

15-
This funny tag syntax is neither a string nor HTML.
15+
Sintaks *tag* aneh ini bukanlah sebuah *string* ataupun *HTML*.
1616

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.
1818

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.
2020

21-
### Why JSX? {#why-jsx}
21+
### Mengapa JSX? {#why-jsx}
2222

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.
2424

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.
2626

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.
2828

29-
With that out of the way, let's get started!
29+
Setelah anda memahaminya, mari kita mulai!
3030

31-
### Embedding Expressions in JSX {#embedding-expressions-in-jsx}
31+
### Menyematkan Ekspresi di JSX {#embedding-expressions-in-jsx}
3232

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)*:
3434

3535
```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>;
3838
3939
ReactDOM.render(
4040
element,
4141
document.getElementById('root')
4242
);
4343
```
4444

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.
4646

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>`.
4848

4949
```js{12}
5050
function formatName(user) {
5151
return user.firstName + ' ' + user.lastName;
5252
}
5353
5454
const user = {
55-
firstName: 'Harper',
56-
lastName: 'Perez'
55+
firstName: 'Budi',
56+
lastName: 'Mahardika'
5757
};
5858
5959
const element = (
6060
<h1>
61-
Hello, {formatName(user)}!
61+
Halo, {formatName(user)}!
6262
</h1>
6363
);
6464
@@ -68,88 +68,88 @@ ReactDOM.render(
6868
);
6969
```
7070

71-
[](codepen://introducing-jsx)
71+
[Coba di CodePen](codepen://introducing-jsx)
7272

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).
7474

75-
### JSX is an Expression Too {#jsx-is-an-expression-too}
75+
### JSX adalah Ekspresi Juga {#jsx-is-an-expression-too}
7676

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.
7878

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:
8080

8181
```js{3,5}
8282
function getGreeting(user) {
8383
if (user) {
84-
return <h1>Hello, {formatName(user)}!</h1>;
84+
return <h1>Halo, {formatName(user)}!</h1>;
8585
}
86-
return <h1>Hello, Stranger.</h1>;
86+
return <h1>Halo, Orang Asing.</h1>;
8787
}
8888
```
8989

90-
### Specifying Attributes with JSX {#specifying-attributes-with-jsx}
90+
### Menentukan Atribut dengan JSX {#specifying-attributes-with-jsx}
9191

92-
You may use quotes to specify string literals as attributes:
92+
Anda dapat menggunakan tanda kutip untuk menentukan *string* literal sebagai atribut:
9393

9494
```js
9595
const element = <div tabIndex="0"></div>;
9696
```
9797

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:
9999

100100
```js
101101
const element = <img src={user.avatarUrl}></img>;
102102
```
103103

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.
105105

106-
>**Warning:**
106+
>**Peringatan:**
107107
>
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.
109109
>
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).
111111
112-
### Specifying Children with JSX {#specifying-children-with-jsx}
112+
### Menspesifikasikan Elemen Anak dengan JSX {#specifying-children-with-jsx}
113113

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:
115115

116116
```js
117117
const element = <img src={user.avatarUrl} />;
118118
```
119119

120-
JSX tags may contain children:
120+
*Tag* JSX dimungkinkan untuk memiliki elemen anak:
121121

122122
```js
123123
const element = (
124124
<div>
125-
<h1>Hello!</h1>
126-
<h2>Good to see you here.</h2>
125+
<h1>Halo!</h1>
126+
<h2>Senang melihatmu di sini.</h2>
127127
</div>
128128
);
129129
```
130130

131-
### JSX Prevents Injection Attacks {#jsx-prevents-injection-attacks}
131+
### JSX Mencegah Serangan Injeksi {#jsx-prevents-injection-attacks}
132132

133-
It is safe to embed user input in JSX:
133+
Anda dapat menanamkan input pengguna di JSX dengan aman:
134134

135135
```js
136136
const title = response.potentiallyMaliciousInput;
137-
// This is safe:
137+
// Ini aman:
138138
const element = <h1>{title}</h1>;
139139
```
140140

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).
142142

143-
### JSX Represents Objects {#jsx-represents-objects}
143+
### JSX Merepresentasikan Objek {#jsx-represents-objects}
144144

145-
Babel compiles JSX down to `React.createElement()` calls.
145+
Babel akan meng-*compile* JSX menjadi pemanggilan `React.createElement()`.
146146

147-
These two examples are identical:
147+
Dua contoh ini akan menghasilkan hal yang sama:
148148

149149
```js
150150
const element = (
151151
<h1 className="greeting">
152-
Hello, world!
152+
Halo, Dunia!
153153
</h1>
154154
);
155155
```
@@ -158,27 +158,27 @@ const element = (
158158
const element = React.createElement(
159159
'h1',
160160
{className: 'greeting'},
161-
'Hello, world!'
161+
'Halo, Dunia!'
162162
);
163163
```
164164

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:
166166

167167
```js
168-
// Note: this structure is simplified
168+
// Catatan: struktur ini sudah disederhanakan
169169
const element = {
170170
type: 'h1',
171171
props: {
172172
className: 'greeting',
173-
children: 'Hello, world!'
173+
children: 'Halo, Dunia!'
174174
}
175175
};
176176
```
177177

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.
179179

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.
181181

182-
>**Tip:**
182+
>**Saran:**
183183
>
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

Comments
 (0)