Skip to content

Commit 1970ebe

Browse files
rizafahmigedeagas
authored andcommitted
Translate typechecking-with-proptypes (#40)
* Translate typechecking-with-proptypes * Revise some stuff: Anda, komentar, and other stuff
1 parent 40aa3f7 commit 1970ebe

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
id: typechecking-with-proptypes
3-
title: Typechecking With PropTypes
3+
title: Pengecekan Tipe Dengan PropTypes
44
permalink: docs/typechecking-with-proptypes.html
55
redirect_from:
66
- "docs/react-api.html#typechecking-with-proptypes"
77
---
88

99
> Note:
1010
>
11-
> `React.PropTypes` has moved into a different package since React v15.5. Please use [the `prop-types` library instead](https://www.npmjs.com/package/prop-types).
11+
> `React.PropTypes` sudah dipindahkan ke paket yang berbeda sejak React v15.5. Silakan gunakan [pustaka `prop-types`](https://www.npmjs.com/package/prop-types).
1212
>
13-
>We provide [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) to automate the conversion.
13+
>Kami menyediakan [*codemod script*](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) untuk melakukan konversi secara otomatis.
1414
15-
As your app grows, you can catch a lot of bugs with typechecking. For some applications, you can use JavaScript extensions like [Flow](https://flow.org/) or [TypeScript](https://www.typescriptlang.org/) to typecheck your whole application. But even if you don't use those, React has some built-in typechecking abilities. To run typechecking on the props for a component, you can assign the special `propTypes` property:
15+
Dengan berkembangnya aplikasi anda, kit dapat menemukan banyak kesalahan atau *bugs* dengan pengecekan tipe. Untuk beberapa aplikasi, anda dapat menggunakan ekstensi JavaScript seperti [Flow](https://flow.org/) atau [TypeScript](https://www.typescriptlang.org/) untuk melakukan pengecekan tipe di aplikasi secara menyeluruh. Meskipun kamu tidak menggunakannya, React memiliki kemampuan pengecekan tipe. Untuk menjalankan pengecekan terhadap *props* disebuah komponen, kamu dapat menggunakan properti khusus `propTypes`:
1616

1717
```javascript
1818
import PropTypes from 'prop-types';
@@ -30,18 +30,18 @@ Greeting.propTypes = {
3030
};
3131
```
3232

33-
`PropTypes` exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're using `PropTypes.string`. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, `propTypes` is only checked in development mode.
33+
`PropTypes` mengirimkan berbagai jenis *validator* yang dapat digunakan untuk memastikan bahwa data yang diterima valid. Contoh diatas, anda menggunakan `PropTypes.string`. Ketika nilai yang dikirimkan untuk sebuah *prop* keliru, sebuah peringatan akan muncul di konsol JavaScript. Untuk alasan performa, `propTypes` hanya melakukan pengecekan di mode pengembangan atau *development*.
3434

3535
### PropTypes {#proptypes}
3636

37-
Here is an example documenting the different validators provided:
37+
Berikut contoh mendokumentasikan berbagai validator yang berbeda yang sudah disediakan:
3838

3939
```javascript
4040
import PropTypes from 'prop-types';
4141

4242
MyComponent.propTypes = {
43-
// You can declare that a prop is a specific JS type. By default, these
44-
// are all optional.
43+
// Anda dapat menyatakan bahwa sebuah prop adalah tipe khusus yang berasal dari JS. Secara default,
44+
// hal ini sifatnya opsional.
4545
optionalArray: PropTypes.array,
4646
optionalBool: PropTypes.bool,
4747
optionalFunc: PropTypes.func,
@@ -50,50 +50,50 @@ MyComponent.propTypes = {
5050
optionalString: PropTypes.string,
5151
optionalSymbol: PropTypes.symbol,
5252

53-
// Anything that can be rendered: numbers, strings, elements or an array
54-
// (or fragment) containing these types.
53+
// Apapun dapat di-render: numbers, strings, elements ataupun sebuah array
54+
// (atau fragmen) yang mengandung tipe-tipe tersebut.
5555
optionalNode: PropTypes.node,
5656

57-
// A React element.
57+
// Sebuah elemen React.
5858
optionalElement: PropTypes.element,
5959

60-
// You can also declare that a prop is an instance of a class. This uses
61-
// JS's instanceof operator.
60+
// Anda dapat juga menyatakan bahwa sebuah prop adalah instance dari sebuah kelas. Ini menggunakan
61+
// operator instanceof dari JS.
6262
optionalMessage: PropTypes.instanceOf(Message),
6363

64-
// You can ensure that your prop is limited to specific values by treating
65-
// it as an enum.
64+
// Anda dapat memastikan bahwa prop anda dibatasi khusus untuk nilai tertentu dengan memperlakukan
65+
// sebagai sebuah enum.
6666
optionalEnum: PropTypes.oneOf(['News', 'Photos']),
6767

68-
// An object that could be one of many types
68+
// Sebuah objek dapat memiliki satu dari banyak tipe-tipe
6969
optionalUnion: PropTypes.oneOfType([
7070
PropTypes.string,
7171
PropTypes.number,
7272
PropTypes.instanceOf(Message)
7373
]),
7474

75-
// An array of a certain type
75+
// Sebuah array dari tipe tertentu
7676
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
7777

78-
// An object with property values of a certain type
78+
// Sebuah objek dengan nilai properti dari tipe tertentu
7979
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
8080

81-
// An object taking on a particular shape
81+
// Sebuah objek yang menerima bentuk tertentu
8282
optionalObjectWithShape: PropTypes.shape({
8383
color: PropTypes.string,
8484
fontSize: PropTypes.number
8585
}),
8686

87-
// You can chain any of the above with `isRequired` to make sure a warning
88-
// is shown if the prop isn't provided.
87+
// Anda dapat merangkai dari contoh diatas dengan `isRequired` untuk memastikan sebuah peringatan
88+
// akan muncul jika sebuah prop tidak disertakan.
8989
requiredFunc: PropTypes.func.isRequired,
9090

91-
// A value of any data type
91+
// Sebuah nilai dari tipe data apapun
9292
requiredAny: PropTypes.any.isRequired,
9393

94-
// You can also specify a custom validator. It should return an Error
95-
// object if the validation fails. Don't `console.warn` or throw, as this
96-
// won't work inside `oneOfType`.
94+
// Anda dapat juga menentukan validator khusus. Akan menghasilkan objek Error
95+
// jika validasi gagal. Jangan `console.warn` atau `throw`, hal seperti ini
96+
// tidak akan berfungsi jika didalam `oneOfType`.
9797
customProp: function(props, propName, componentName) {
9898
if (!/matchme/.test(props[propName])) {
9999
return new Error(
@@ -103,11 +103,11 @@ MyComponent.propTypes = {
103103
}
104104
},
105105

106-
// You can also supply a custom validator to `arrayOf` and `objectOf`.
107-
// It should return an Error object if the validation fails. The validator
108-
// will be called for each key in the array or object. The first two
109-
// arguments of the validator are the array or object itself, and the
110-
// current item's key.
106+
// Anda dapat juga menyediakan sebuah validator tambahan ke `arrayOf` dan `objectOf`.
107+
// Hal ini sebaiknya menghasilkan objek Error jika validasi gagal. Validator
108+
// akan dipanggil untuk setiap nilai didalam array atau objek. Dua pertama
109+
// dari argumen validator adalah array atau objek itu sendiri, dan
110+
// identitas dari nilai saat itu.
111111
customArrayProp: PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
112112
if (!/matchme/.test(propValue[key])) {
113113
return new Error(
@@ -119,16 +119,16 @@ MyComponent.propTypes = {
119119
};
120120
```
121121

122-
### Requiring Single Child {#requiring-single-child}
122+
### Membutuhkan Satu Komponen Anak {#requiring-single-child}
123123

124-
With `PropTypes.element` you can specify that only a single child can be passed to a component as children.
124+
Dengan menggunakan `PropTypes.element` anda dapat menentukan bahwa hanya menerima satu komponen anak yang dapat dikirimkan ke komponen lain.
125125

126126
```javascript
127127
import PropTypes from 'prop-types';
128128

129129
class MyComponent extends React.Component {
130130
render() {
131-
// This must be exactly one element or it will warn.
131+
// Harus memiliki hanya satu elemen atau akan diberi peringatan.
132132
const children = this.props.children;
133133
return (
134134
<div>
@@ -143,9 +143,9 @@ MyComponent.propTypes = {
143143
};
144144
```
145145

146-
### Default Prop Values {#default-prop-values}
146+
### Nilai Default Prop {#default-prop-values}
147147

148-
You can define default values for your `props` by assigning to the special `defaultProps` property:
148+
Anda dapat mendefinisikan nilai *default* untuk `props` dengan menambahkan properti khusus `defaultProps`:
149149

150150
```javascript
151151
class Greeting extends React.Component {
@@ -156,19 +156,19 @@ class Greeting extends React.Component {
156156
}
157157
}
158158

159-
// Specifies the default values for props:
159+
// Menentukan nilai default dari props:
160160
Greeting.defaultProps = {
161161
name: 'Stranger'
162162
};
163163

164-
// Renders "Hello, Stranger":
164+
// Render "Hello, Stranger":
165165
ReactDOM.render(
166166
<Greeting />,
167167
document.getElementById('example')
168168
);
169169
```
170170

171-
If you are using a Babel transform like [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) , you can also declare `defaultProps` as static property within a React component class. This syntax has not yet been finalized though and will require a compilation step to work within a browser. For more information, see the [class fields proposal](https://github.com/tc39/proposal-class-fields).
171+
Jika kamu menggunakan alat transformasi Babel seperti [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) , kamu dapat mendeklarasikan `defaultProps` sebagai properti *static* dalam komponen kelas React. Sintaks ini belum final dan akan membutuhkan tahapan kompilasi untuk berjalan di browser. Informasi lebih lanjut, silakan lihat [proposal class fields](https://github.com/tc39/proposal-class-fields).
172172

173173
```javascript
174174
class Greeting extends React.Component {
@@ -184,4 +184,4 @@ class Greeting extends React.Component {
184184
}
185185
```
186186

187-
The `defaultProps` will be used to ensure that `this.props.name` will have a value if it was not specified by the parent component. The `propTypes` typechecking happens after `defaultProps` are resolved, so typechecking will also apply to the `defaultProps`.
187+
Properti `defaultProps` akan digunakan untuk memastikan bahwa `this.props.name` akan memiliki sebuah nilai jika tidak ada nilai yang diberikan oleh komponen induknya. Proses pengecekan tipe `propTypes` akan dijalankan setelah `defaultProps` berjalan, sehingga proses pengecekan tipe juga akan berlaku untuk `defaultProps`.

0 commit comments

Comments
 (0)