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
Call`createElement`to create a React element with the given `type`, `props`, and`children`.
23
+
Panggil`createElement`untuk membuat elemen React dengan parameter `type`, `props`, dan`children`.
24
24
25
25
```js
26
26
import { createElement } from'react';
@@ -34,44 +34,44 @@ function Greeting({ name }) {
34
34
}
35
35
```
36
36
37
-
[See more examples below.](#usage)
37
+
[Lihat lebih banyak contoh lainnya di bawah ini.](#usage)
38
38
39
-
#### Parameters {/*parameters*/}
39
+
#### Parameter {/*parameters*/}
40
40
41
-
*`type`: The`type`argument must be a valid React component type. For example, it could be a tag name string (such as `'div'`or`'span'`), or a React component (a function, a class, or a special component like[`Fragment`](/reference/react/Fragment)).
41
+
*`type`: Argument`type`harus berupa tipe komponen React yang valid. Misalnya, bisa berupa string nama tag (seperti `'div'`atau`'span'`), atau komponen React (fungsi, kelas, atau komponen khusus seperti[`Fragment`](/reference/react/Fragment)).
42
42
43
-
*`props`: The`props`argument must either be an object or `null`. If you pass`null`, it will be treated the same as an empty object. React will create an element with props matching the `props`you have passed. Note that`ref`and`key`from your`props`object are special and will *not* be available as`element.props.ref`and`element.props.key`on the returned `element`. They will be available as `element.ref`and`element.key`.
43
+
*`props`: Argumen`props`harus berupa objek atau `null`. Jika Anda mengoper`null`, itu akan diperlakukan sama seperti objek kosong. React akan membuat elemen dengan *props* yang cocok dengan `props`yang telah Anda oper. Perhatikan bahwa`ref`dan`key`dari objek`props`Anda adalah spesial dan *tidak* akan tersedia sebagai`element.props.ref`dan`element.props.key`pada `element` yang dikembalikan. Mereka akan tersedia sebagai `element.ref`dan`element.key`.
44
44
45
-
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and`false`), and arrays of React nodes.
45
+
***optional**`...children`: Nol atau lebih simpul anak. Mereka bisa berupa simpul React apa saja, termasuk elemen React, string, angka, [portal](/reference/react-dom/createPortal), simpul kosong (`null`, `undefined`, `true`, dan`false`), dan array simpul React.
46
46
47
-
#### Returns {/*returns*/}
47
+
#### Kembalian {/*returns*/}
48
48
49
-
`createElement`returns a React element object with a few properties:
49
+
`createElement`mengembalikan objek elemen React dengan beberapa properti:
50
50
51
-
*`type`: The `type`you have passed.
52
-
*`props`: The `props`you have passed except for `ref`and`key`. If the `type`is a component with legacy `type.defaultProps`, then any missing or undefined `props`will get the values from`type.defaultProps`.
53
-
*`ref`: The `ref`you have passed. If missing, `null`.
54
-
*`key`: The `key`you have passed, coerced to a string. If missing, `null`.
51
+
*`type`: `type`yang telah Anda oper.
52
+
*`props`: `props`yang telah Anda oper kecuali untuk `ref`dan`key`. Jika `type`adalah komponen *legacy*`type.defaultProps`, lalu ada yang hilang atau tidak terdefinisi `props`akan mendapatkan nilai dari`type.defaultProps`.
53
+
*`ref`: `ref`yang telah Anda oper. Jika hilang, `null`.
54
+
*`key`: `key`yang telah Anda oper, dipaksa untuk string. Jika hilang, `null`.
55
55
56
-
Usually, you'll return the element from your component or make it a child of another element. Although you may read the element's properties, it's best to treat every element as opaque after it's created, and only render it.
56
+
Biasanya, Anda akan mengembalikan elemen dari komponen Anda atau menjadikannya anak dari elemen lain. Meskipun Anda dapat membaca properti elemen, yang terbaik adalah memperlakukan setiap elemen sebagai buram setelah dibuat, dan hanya me-*render*-nya.
57
57
58
-
#### Caveats {/*caveats*/}
58
+
#### Catatan penting {/*caveats*/}
59
59
60
-
*You must**treat React elements and their props as [immutable](https://en.wikipedia.org/wiki/Immutable_object)**and never change their contents after creation. In development, React will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)the returned element and its `props`property shallowly to enforce this.
60
+
*Anda harus**memperlakukan elemen React dan propertinya sebagai [*Immutable*](https://en.wikipedia.org/wiki/Immutable_object)**dan tidak pernah mengubah isinya setelah dibuat. Dalam pengembangan, React akan [membekukan](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)elemen yang dikembalikan dan `props`properti dangkal untuk menegakkan ini.
61
61
62
-
*When you use JSX, **you must start a tag with a capital letter to render your own custom component.**In other words, `<Something />`is equivalent to `createElement(Something)`, but`<something />` (lowercase) is equivalent to `createElement('something')` (note it's a string, so it will be treated as a built-in HTML tag).
62
+
*Saat Anda menggunakan JSX, **Anda harus memulai tag dengan huruf kapital untuk me-*render* komponen kustom Anda sendiri.**Dengan kata lain, `<Something />`setara dengan `createElement(Something)`, tetapi`<something />` (huruf kecil) setara dengan `createElement('something')` (perhatikan itu adalah string, sehingga akan diperlakukan sebagai tag HTML bawaan).
63
63
64
-
*You should only**pass children as multiple arguments to`createElement`if they are all statically known,**like`createElement('h1', {}, child1, child2, child3)`. If your children are dynamic, pass the entire array as the third argument: `createElement('ul', {}, listItems)`. This ensures that React will [warn you about missing `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key)for any dynamic lists. For static lists this is not necessary because they never reorder.
64
+
*Anda hanya boleh**mengoper anak sebagai beberapa argumen untuk`createElement`jika semuanya diketahui secara statis,**seperti`createElement('h1', {}, child1, child2, child3)`. Jika anak Anda dinamis, oper seluruh array sebagai argumen ketiga: `createElement('ul', {}, listItems)`. Ini memastikan bahwa React akan [memperingatkan Anda tentang *`key`* yang hilang](/learn/rendering-lists#keeping-list-items-in-order-with-key)untuk setiap daftar dinamis. Untuk daftar statis ini tidak diperlukan karena mereka tidak pernah menyusun ulang.
65
65
66
66
---
67
67
68
-
## Usage {/*usage*/}
68
+
## Penggunaan {/*usage*/}
69
69
70
-
### Creating an element without JSX {/*creating-an-element-without-jsx*/}
70
+
### Membuat elemen tanpa JSX {/*creating-an-element-without-jsx*/}
71
71
72
-
If you don't like[JSX](/learn/writing-markup-with-jsx)or can't use it in your project, you can use`createElement`as an alternative.
72
+
Jika Anda tidak menyukai[JSX](/learn/writing-markup-with-jsx)atau tidak dapat menggunakannya dalam proyek Anda, Anda dapat menggunakan`createElement`sebagai alternatif.
73
73
74
-
To create an element without JSX, call`createElement`with some <CodeStepstep={1}>type</CodeStep>, <CodeStepstep={2}>props</CodeStep>, and <CodeStepstep={3}>children</CodeStep>:
74
+
Untuk membuat elemen tanpa JSX, panggil`createElement`dengan beberapa <CodeStepstep={1}>type</CodeStep>, <CodeStepstep={2}>*props*</CodeStep>, dan <CodeStepstep={3}>children</CodeStep>:
The <CodeStepstep={3}>children</CodeStep> are optional, and you can pass as many as you need (the example above has three children). This code will display a`<h1>`header with a greeting. For comparison, here is the same example rewritten with JSX:
90
+
<CodeStepstep={3}>Anak</CodeStep> bersifat *optional*, dan Anda dapat mengoper sebanyak yang Anda butuhkan (contoh di atas memiliki tiga anak). Kode ini akan menampilkan header`<h1>`dengan salam. Sebagai perbandingan, berikut adalah contoh yang sama yang ditulis ulang dengan JSX:
Here is a complete example written with`createElement`:
118
+
Berikut adalah contoh lengkap yang ditulis dengan`createElement`:
119
119
120
120
<Sandpack>
121
121
@@ -149,7 +149,7 @@ export default function App() {
149
149
150
150
</Sandpack>
151
151
152
-
And here is the same example written using JSX:
152
+
Dan berikut adalah contoh yang sama yang ditulis menggunakan JSX:
153
153
154
154
<Sandpack>
155
155
@@ -176,13 +176,13 @@ export default function App() {
176
176
177
177
</Sandpack>
178
178
179
-
Both coding styles are fine, so you can use whichever one you prefer for your project. The main benefit of using JSX compared to`createElement`is that it's easy to see which closing tag corresponds to which opening tag.
179
+
Kedua gaya pengkodean baik-baik saja, sehingga Anda dapat menggunakan mana yang Anda sukai untuk proyek Anda. Manfaat utama menggunakan JSX dibandingkan dengan`createElement`adalah mudah untuk melihat tag penutup mana yang sesuai dengan tag pembuka mana.
180
180
181
181
<DeepDive>
182
182
183
-
#### What is a React element, exactly? {/*what-is-a-react-element-exactly*/}
183
+
#### Apa itu elemen React, tepatnya? {/*what-is-a-react-element-exactly*/}
184
184
185
-
An element is a lightweight description of a piece of the user interface. For example, both`<Greeting name="Taylor" />`and`createElement(Greeting, { name: 'Taylor' })`produce an object like this:
185
+
Elemen adalah deskripsi ringan dari bagian antarmuka pengguna. Misalnya, keduanya`<Greeting name="Taylor" />`dan`createElement(Greeting, { name: 'Taylor' })`menghasilkan objek seperti ini:
186
186
187
187
```js
188
188
// Slightly simplified
@@ -196,10 +196,10 @@ An element is a lightweight description of a piece of the user interface. For ex
196
196
}
197
197
```
198
198
199
-
**Note that creating this object does not render the`Greeting`component or create any DOM elements.**
199
+
**Perhatikan bahwa membuat objek ini tidak me-*render* komponen`Greeting`atau membuat elemen DOM apa pun.**
200
200
201
-
A React element is more like a description--an instruction for React to later render the`Greeting`component. By returning this object from your`App`component, you tell React what to do next.
201
+
Elemen React lebih seperti deskripsi—instruksi untuk React untuk me-*render* komponen`Greeting`nanti. Dengan mengembalikan objek ini dari komponen`App`Anda, Anda memberi tahu React apa yang harus dilakukan selanjutnya.
202
202
203
-
Creating elements is extremely cheap so you don't need to try to optimize or avoid it.
203
+
Membuat elemen sangatlah murah sehingga Anda tidak perlu mencoba mengoptimalkan atau menghindarinya.
0 commit comments