Skip to content

Commit fe6c8d1

Browse files
committed
Translated React Without ES6
1 parent b8eda4e commit fe6c8d1

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

content/docs/react-without-es6.md

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
---
22
id: react-without-es6
3-
title: React Without ES6
3+
title: React Tanpa ES6
44
permalink: docs/react-without-es6.html
55
---
66

7-
Normally you would define a React component as a plain JavaScript class:
7+
Umumnya Anda mendefinisikan komponen React sebagai kelas JavaScript biasa:
88

99
```javascript
1010
class Greeting extends React.Component {
1111
render() {
12-
return <h1>Hello, {this.props.name}</h1>;
12+
return <h1>Halo {this.props.name}</h1>;
1313
}
1414
}
1515
```
1616

17-
If you don't use ES6 yet, you may use the `create-react-class` module instead:
17+
Jika Anda belum menggunakan ES6, Anda bisa menggunakan modul `create-react-class`:
1818

1919

2020
```javascript
2121
var createReactClass = require('create-react-class');
2222
var Greeting = createReactClass({
2323
render: function() {
24-
return <h1>Hello, {this.props.name}</h1>;
24+
return <h1>Halo {this.props.name}</h1>;
2525
}
2626
});
2727
```
2828

29-
The API of ES6 classes is similar to `createReactClass()` with a few exceptions.
29+
API untuk kelas ES6 mirip dengan `createReactClass()`, dengan beberapa pengecualian.
3030

31-
## Declaring Default Props {#declaring-default-props}
31+
## Mendeklarasikan *Props* *Default* {#declaring-default-props}
3232

33-
With functions and ES6 classes `defaultProps` is defined as a property on the component itself:
33+
Dengan kelas dan fungsi ES6, `defaultProps` didefinisikan sebagai properti komponennya sendiri:
3434

3535
```javascript
3636
class Greeting extends React.Component {
3737
// ...
3838
}
3939

4040
Greeting.defaultProps = {
41-
name: 'Mary'
41+
name: 'Maria'
4242
};
4343
```
4444

45-
With `createReactClass()`, you need to define `getDefaultProps()` as a function on the passed object:
45+
Dengan `createReactClass()`, Anda harus mendefinisikan `getDefaultProps()` sebagai fungsi pada objek yang dioperkan:
4646

4747
```javascript
4848
var Greeting = createReactClass({
4949
getDefaultProps: function() {
5050
return {
51-
name: 'Mary'
51+
name: 'Maria'
5252
};
5353
},
5454

@@ -57,9 +57,9 @@ var Greeting = createReactClass({
5757
});
5858
```
5959

60-
## Setting the Initial State {#setting-the-initial-state}
60+
## Menyetel *State* Awal {#setting-the-initial-state}
6161

62-
In ES6 classes, you can define the initial state by assigning `this.state` in the constructor:
62+
Pada kelas ES6, Anda bisa mendefinisikan *state* awal dengan menetapkan `this.state` pada konstruktor:
6363

6464
```javascript
6565
class Counter extends React.Component {
@@ -71,7 +71,7 @@ class Counter extends React.Component {
7171
}
7272
```
7373

74-
With `createReactClass()`, you have to provide a separate `getInitialState` method that returns the initial state:
74+
Dengan `createReactClass()`, Anda harus menyediakan *method* `getInitialState` terpisah yang mengembalikan *state* awal:
7575

7676
```javascript
7777
var Counter = createReactClass({
@@ -82,16 +82,16 @@ var Counter = createReactClass({
8282
});
8383
```
8484

85-
## Autobinding {#autobinding}
85+
## *Autobinding* {#autobinding}
8686

87-
In React components declared as ES6 classes, methods follow the same semantics as regular ES6 classes. This means that they don't automatically bind `this` to the instance. You'll have to explicitly use `.bind(this)` in the constructor:
87+
Pada komponen React yang dideklarasikan sebagai kelas ES6, *method* mengikuti semantik yang sama seperti kelas ES6 reguler. Ini berarti *method* tersebut tidak secara otomatis mem-*bind* `this` kepada instans. Anda harus secara eksplisit menggunakan `.bind(this)` pada konstruktor:
8888

8989
```javascript
9090
class SayHello extends React.Component {
9191
constructor(props) {
9292
super(props);
93-
this.state = {message: 'Hello!'};
94-
// This line is important!
93+
this.state = {message: 'Halo!'};
94+
// Baris berikut penting!
9595
this.handleClick = this.handleClick.bind(this);
9696
}
9797

@@ -100,22 +100,23 @@ class SayHello extends React.Component {
100100
}
101101

102102
render() {
103-
// Because `this.handleClick` is bound, we can use it as an event handler.
103+
// Karena `this.handleClick` telah di-bind, kita bisa menggunakannya
104+
// sebagai event handler.
104105
return (
105106
<button onClick={this.handleClick}>
106-
Say hello
107+
Ucapkan halo
107108
</button>
108109
);
109110
}
110111
}
111112
```
112113

113-
With `createReactClass()`, this is not necessary because it binds all methods:
114+
Dengan `createReactClass()`, hal tersebut tidak diperlukan karena semua *method* akan di-*bind*:
114115

115116
```javascript
116117
var SayHello = createReactClass({
117118
getInitialState: function() {
118-
return {message: 'Hello!'};
119+
return {message: 'Halo!'};
119120
},
120121

121122
handleClick: function() {
@@ -125,61 +126,61 @@ var SayHello = createReactClass({
125126
render: function() {
126127
return (
127128
<button onClick={this.handleClick}>
128-
Say hello
129+
Ucapkan halo
129130
</button>
130131
);
131132
}
132133
});
133134
```
134135

135-
This means writing ES6 classes comes with a little more boilerplate code for event handlers, but the upside is slightly better performance in large applications.
136+
Ini berarti penulisan dengan kelas ES6 disertai dengan kode *boilerplate* untuk *event handler* tetapi manfaatnya adalah kinerja yang sedikit lebih baik dalam aplikasi yang besar.
136137

137-
If the boilerplate code is too unattractive to you, you may enable the **experimental** [Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/) syntax proposal with Babel:
138+
Jika kode *boilerplate* sangat tidak menarik bagi Anda, Anda bisa mengaktifkan sintaksis [*Class Property*](https://babeljs.io/docs/plugins/transform-class-properties/) yang bersifat **eksperimental** dengan Babel:
138139

139140

140141
```javascript
141142
class SayHello extends React.Component {
142143
constructor(props) {
143144
super(props);
144-
this.state = {message: 'Hello!'};
145+
this.state = {message: 'Halo!'};
145146
}
146-
// WARNING: this syntax is experimental!
147-
// Using an arrow here binds the method:
147+
// PERINGATAN: sintalsis ini bersifat eksperimental!
148+
// Menggunakan *arrow* akan mem-bind method:
148149
handleClick = () => {
149150
alert(this.state.message);
150151
}
151152

152153
render() {
153154
return (
154155
<button onClick={this.handleClick}>
155-
Say hello
156+
Ucapkan halo
156157
</button>
157158
);
158159
}
159160
}
160161
```
161162

162-
Please note that the syntax above is **experimental** and the syntax may change, or the proposal might not make it into the language.
163+
Perhatikan bahwa sintaksis di atas bersifat **eksperimental** dan sintaksis mungkin akan berubah, atau proposal ini tidak akan disertakan dalam bahasa.
163164

164-
If you'd rather play it safe, you have a few options:
165+
Jika Anda ingin bermain pada area yang aman, Anda memiliki beberapa opsi:
165166

166-
* Bind methods in the constructor.
167-
* Use arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`.
168-
* Keep using `createReactClass`.
167+
* Mem-*bind* *method* dalam konstruktor.
168+
* Gunakan *arrow function*, misalnya `onClick={(e) => this.handleClick(e)}`.
169+
* Terus gunakan `createReactClass`.
169170

170-
## Mixins {#mixins}
171+
## Mixin {#mixins}
171172

172-
>**Note:**
173+
>**Catatan:**
173174
>
174-
>ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes.
175+
>ES6 diluncurkan tanpa adanya dukungan *mixin*. Oleh sebab itu, tidak ada dukungan untuk *mixin* saat Anda menggunakan React dengan kelas ES6.
175176
>
176-
>**We also found numerous issues in codebases using mixins, [and don't recommend using them in the new code](/blog/2016/07/13/mixins-considered-harmful.html).**
177+
>**Kami juga menemukan banyak masalah pada kode dasar yang menggunakan *mixin*, [dan tidak menyarankan untuk menggunakannya untuk kode yang baru](/blog/2016/07/13/mixins-considered-harmful.html).**
177178
>
178-
>This section exists only for the reference.
179+
>Bagian berikut hanya digunakan untuk rujukan.
179180
180-
Sometimes very different components may share some common functionality. These are sometimes called [cross-cutting concerns](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass` lets you use a legacy `mixins` system for that.
181+
Terkadang komponen yang sangat berbeda bisa berbagi fungsionalitas yang sama. Hal ini terkadang disebut sebagai [*cross-cutting concern*](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass` memungkinkan Anda untuk menggunakan sistem `mixin` yang bersifat *legacy* untuk hal tersebut.
181182

182-
One common use case is a component wanting to update itself on a time interval. It's easy to use `setInterval()`, but it's important to cancel your interval when you don't need it anymore to save memory. React provides [lifecycle methods](/docs/react-component.html#the-component-lifecycle) that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide an easy `setInterval()` function that will automatically get cleaned up when your component is destroyed.
183+
Salah satu kasus penggunaan yang umum adalah sebuah komponen ingin memperbarui dirinya sendiri secara periodik. Sangat mudah untuk menggunakan `setInterval()`, tetapi sangat penting untuk membatalkan interval jika Anda tidak membutuhkannya lagi untuk menghemat memori. React menyediakan [*lifecycle method*](/docs/react-component.html#the-component-lifecycle) yang bisa memberi tahu Anda kapan komponen akan diciptakan atau dihancurkan. Sebagai contoh, mari kita buat *mixin* yang sederhana yang menggunakan *method* berikut untuk menyediakan fungsi `setInterval()` yang mudah, yang akan dibersihkan secara otomatis ketika komponen Anda dihancurkan.
183184

184185
```javascript
185186
var SetIntervalMixin = {
@@ -197,20 +198,20 @@ var SetIntervalMixin = {
197198
var createReactClass = require('create-react-class');
198199

199200
var TickTock = createReactClass({
200-
mixins: [SetIntervalMixin], // Use the mixin
201+
mixins: [SetIntervalMixin], // Gunakan mixin
201202
getInitialState: function() {
202203
return {seconds: 0};
203204
},
204205
componentDidMount: function() {
205-
this.setInterval(this.tick, 1000); // Call a method on the mixin
206+
this.setInterval(this.tick, 1000); // Panggil method pada mixin
206207
},
207208
tick: function() {
208209
this.setState({seconds: this.state.seconds + 1});
209210
},
210211
render: function() {
211212
return (
212213
<p>
213-
React has been running for {this.state.seconds} seconds.
214+
React telah berjalan selama {this.state.seconds} detik.
214215
</p>
215216
);
216217
}
@@ -222,4 +223,4 @@ ReactDOM.render(
222223
);
223224
```
224225

225-
If a component is using multiple mixins and several mixins define the same lifecycle method (i.e. several mixins want to do some cleanup when the component is destroyed), all of the lifecycle methods are guaranteed to be called. Methods defined on mixins run in the order mixins were listed, followed by a method call on the component.
226+
Jika komponen menggunakan beberapa *mixin* dan beberapa *mixin* mendefinisikan *lifecycle method* yang sama (beberapa *mixin* ingin melakukan pembersihan ketika komponen dihancurkan), semua *lifecycle method* dijamin untuk dipanggil. *Method* yang didefiniskan pada *mixin* dijalankan secara berurutan sesuai dengan dengan proses pendaftarannya, diikuti dengan pemanggilan *method* pada komponen.

0 commit comments

Comments
 (0)