Skip to content

Commit 42594ed

Browse files
aroyanr17xmazipanmhaidarhanif
committed
New Indonesian translation: importing and exporting components (#345)
Co-authored-by: RiN <hi@rin.rocks> Co-authored-by: Irfan Maulana <mazipanneh@gmail.com> Co-authored-by: M Haidar Hanif <git@mhaidarhanif.com>
1 parent aaa0048 commit 42594ed

File tree

1 file changed

+65
-64
lines changed

1 file changed

+65
-64
lines changed

src/content/learn/importing-and-exporting-components.md

+65-64
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
2-
title: Importing and Exporting Components
2+
title: Mengimpor dan Mengekspor Komponen
33
---
44

55
<Intro>
66

7-
The magic of components lies in their reusability: you can create components that are composed of other components. But as you nest more and more components, it often makes sense to start splitting them into different files. This lets you keep your files easy to scan and reuse components in more places.
7+
Keajaiban komponen terletak pada kemampuannya yang dapat digunakan kembali: Anda dapat membuat komponen yang disusun dengan komponen lain. Namun, ketika Anda menyusun komponen-komponen yang semakin banyak, seringkali lebih masuk akal untuk mulai membaginya ke dalam *file-file* yang berbeda. Dengan ini Anda menjaga *file* Anda agar tetap mudah dipindai dan digunakan kembali di banyak tempat.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* What a root component file is
14-
* How to import and export a component
15-
* When to use default and named imports and exports
16-
* How to import and export multiple components from one file
17-
* How to split components into multiple files
13+
* Apa itu *file* komponen root
14+
* Bagaimana cara impor dan ekspor komponen
15+
* Kapan menggunakan default dan named impor dan ekspor
16+
* Bagaimana cara mengimpor dan mengekspor beberapa komponen pada satu *file*
17+
* Bagaimana cara memisahkan komponen menjadi beberapa *file*
1818

1919
</YouWillLearn>
2020

21-
## The root component file {/*the-root-component-file*/}
21+
## File komponen root {/*the-root-component-file*/}
2222

23-
In [Your First Component](/learn/your-first-component), you made a `Profile` component and a `Gallery` component that renders it:
23+
Pada [Komponen Pertama Anda](/learn/your-first-component), Anda membuat komponen `Profile` dan komponen `Gallery` yang merender:
2424

2525
<Sandpack>
2626

@@ -37,7 +37,7 @@ function Profile() {
3737
export default function Gallery() {
3838
return (
3939
<section>
40-
<h1>Amazing scientists</h1>
40+
<h1>Para ilmuwan hebat</h1>
4141
<Profile />
4242
<Profile />
4343
<Profile />
@@ -52,17 +52,17 @@ img { margin: 0 10px 10px 0; height: 90px; }
5252

5353
</Sandpack>
5454

55-
These currently live in a **root component file,** named `App.js` in this example. In [Create React App](https://create-react-app.dev/), your app lives in `src/App.js`. Depending on your setup, your root component could be in another file, though. If you use a framework with file-based routing, such as Next.js, your root component will be different for every page.
55+
Komponen tersebut saat ini berada pada **file komponen root,** yang bernama `App.js` pada contoh ini. Pada [Create React App](https://create-react-app.dev/), aplikasi Anda berada di `src/App.js`. Tergantung pada persiapan Anda, komponen root Anda bisa saja berada di *file* lain. Jika Anda menggunakan framework dengan *file-based routing*, seperti Next.js, komponen root Anda akan berbeda di setiap halaman.
5656

57-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57+
## Mengekspor dan mengimpor sebuah komponen {/*exporting-and-importing-a-component*/}
5858

59-
What if you want to change the landing screen in the future and put a list of science books there? Or place all the profiles somewhere else? It makes sense to move `Gallery` and `Profile` out of the root component file. This will make them more modular and reusable in other files. You can move a component in three steps:
59+
Bagaimana jika Anda ingin mengubah *landing screen* di masa depan dan memasukkan daftar buku sains disana? Atau meletakkan semua profil di tempat lain? Masuk akal untuk memindahkan `Gallery` dan `Profile` dari *file* komponen root. Ini akan membuat lebih modular dan dapat digunakan kembali di *file* lain. Anda dapat memindahkan sebuah komponen dengan tiga langkah:
6060

61-
1. **Make** a new JS file to put the components in.
62-
2. **Export** your function component from that file (using either [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports) exports).
63-
3. **Import** it in the file where you’ll use the component (using the corresponding technique for importing [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module) exports).
61+
1. **Buat** sebuah *file* JS baru untuk memasukkan komponen.
62+
2. **Ekspor** function component Anda dari *file* tersebut (menggunakan baik [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) atau [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports) eskpor).
63+
3. **Impor** dimana Anda akan menggunakan komponen tersebut (menggunakan teknik yang sesuai untuk mengimpor [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) atau [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module) ekspor).
6464

65-
Here both `Profile` and `Gallery` have been moved out of `App.js` into a new file called `Gallery.js`. Now you can change `App.js` to import `Gallery` from `Gallery.js`:
65+
Di sini `Profile` dan `Gallery` sudah dipindahkan dari `App.js` ke dalam *file* baru bernama `Gallery.js`. Sekarang Anda dapat mengubah `App.js` untuk mengimpor `Gallery` dari `Gallery.js`:
6666

6767
<Sandpack>
6868

@@ -89,7 +89,7 @@ function Profile() {
8989
export default function Gallery() {
9090
return (
9191
<section>
92-
<h1>Amazing scientists</h1>
92+
<h1>Para ilmuwan hebat</h1>
9393
<Profile />
9494
<Profile />
9595
<Profile />
@@ -104,82 +104,83 @@ img { margin: 0 10px 10px 0; height: 90px; }
104104

105105
</Sandpack>
106106

107-
Notice how this example is broken down into two component files now:
107+
Perhatikan bagaimana pada contoh ini dipecah menjadi dua *file* komponen sekarang:
108108

109109
1. `Gallery.js`:
110-
- Defines the `Profile` component which is only used within the same file and is not exported.
111-
- Exports the `Gallery` component as a **default export.**
110+
- Mendefinisikan `Profile` komponen yang hanya digunakan dalam *file* yang sama dan tidak diekspor.
111+
- Mengekspor `Gallery` komponen sebagai **default export.**
112112
2. `App.js`:
113-
- Imports `Gallery` as a **default import** from `Gallery.js`.
114-
- Exports the root `App` component as a **default export.**
113+
- Mengimpor `Gallery` sebagai **default import** dari `Gallery.js`.
114+
- Mengekspor root `App` komponen sebagai **default export.**
115115

116116

117117
<Note>
118118

119-
You may encounter files that leave off the `.js` file extension like so:
119+
Anda mungkin menemukan *file* yang meninggalkan ekstensi *file* `.js` seperti ini:
120120

121121
```js
122122
import Gallery from './Gallery';
123123
```
124124

125-
Either `'./Gallery.js'` or `'./Gallery'` will work with React, though the former is closer to how [native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules) work.
125+
Salah satu `'./Gallery.js'` atau `'./Gallery'` akan jalan dengan React, meskipun yang pertama lebih mirip dengan bagaimana [native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules) bekerja.
126126

127127
</Note>
128128

129129
<DeepDive>
130130

131-
#### Default vs named exports {/*default-vs-named-exports*/}
131+
#### Default vs named ekspor {/*default-vs-named-exports*/}
132132

133-
There are two primary ways to export values with JavaScript: default exports and named exports. So far, our examples have only used default exports. But you can use one or both of them in the same file. **A file can have no more than one _default_ export, but it can have as many _named_ exports as you like.**
133+
Ada dua cara utama untuk mengekspor nilai dengan JavaScript: **default exports** dan **named exports**. Sejauh ini, contoh kita hanya menggunakan **default exports**. Tapi Anda dapat menggunakan satu atau keduanya pada *file* yang sama. **Sebuah file dapat menggunakan tidak lebih dari satu _default_ export, tapi dapat menggunakan _named_ exports sebanyak yang Anda suka.**
134134

135-
![Default and named exports](/images/docs/illustrations/i_import-export.svg)
135+
![Default dan named ekspor](/images/docs/illustrations/i_import-export.svg)
136136

137-
How you export your component dictates how you must import it. You will get an error if you try to import a default export the same way you would a named export! This chart can help you keep track:
137+
Bagaimana Anda mengekspor komponen Anda mendikte bagaimana Anda harus mengimpornya. Anda akan mendapatkan error jika Anda mencoba untuk mengimpor **default exports** dengan cara yang sama Anda menggunakan **named exports**! Tabel ini akan membantu Anda untuk melacak:
138138

139-
| Syntax | Export statement | Import statement |
139+
| Sintaksis | Pernyataan Expor | Pernyataan Impor |
140140
| ----------- | ----------- | ----------- |
141141
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
142142
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
143143

144-
When you write a _default_ import, you can put any name you want after `import`. For example, you could write `import Banana from './Button.js'` instead and it would still provide you with the same default export. In contrast, with named imports, the name has to match on both sides. That's why they are called _named_ imports!
144+
Ketika Anda menulis **default imports**, Anda dapat memberi nama apa saja setelah `import`. Contoh, Anda dapat menulis `import Banana from './Button.js'` dan itu akan tetap memberi Anda `export default` yang sama. Sebaliknya, dengan **named imports**, nama harus sama di kedua sisi. Itulah mengapa disebut **named imports**!
145145

146-
**People often use default exports if the file exports only one component, and use named exports if it exports multiple components and values.** Regardless of which coding style you prefer, always give meaningful names to your component functions and the files that contain them. Components without names, like `export default () => {}`, are discouraged because they make debugging harder.
146+
**Orang-orang seringkali menggunakan `default exports` jika *file* yang diekspor hanya satu komponen, dan menggunakan `named exports` jika mengekspor beberapa komponen dan nilai.** Bagaimanapun gaya koding yang Anda gunakan, selalu beri nama yang berarti pada fungsi komponen Anda dan isi *file* tersebut. Komponen tanpa nama, seperti `export default () => {}`, tidak disarankan karena membuat proses debug lebih sulit.
147147

148148
</DeepDive>
149149

150-
## Exporting and importing multiple components from the same file {/*exporting-and-importing-multiple-components-from-the-same-file*/}
150+
## Mengekspor dan mengimpor beberapa komponen dari file yang sama {/*exporting-and-importing-multiple-components-from-the-same-file*/}
151151

152-
What if you want to show just one `Profile` instead of a gallery? You can export the `Profile` component, too. But `Gallery.js` already has a *default* export, and you can't have _two_ default exports. You could create a new file with a default export, or you could add a *named* export for `Profile`. **A file can only have one default export, but it can have numerous named exports!**
152+
Bagaimana jika Anda ingin menampilkan hanya satu `Profile` selain sebuah galeri? Anda dapat mengekspor komponen `Profile` juga. Tapi `Gallery.js` telah menggunakan **default exports**, dan Anda tidak dapat memiliki _dua_ **default exports**. Anda dapat membuat *file* baru dengan **default exports**, atau Anda dapat menambahkan sebuah **named exports** untuk `Profile`. **Sebuah *file* hanya dapat memiliki satu `default exports`, tapi dapat memiliki banyak `named exports`!**
153153

154154
<Note>
155155

156-
To reduce the potential confusion between default and named exports, some teams choose to only stick to one style (default or named), or avoid mixing them in a single file. Do what works best for you!
156+
Untuk mengurangi potensi kebingunan antara **default** dan **named exports**, beberapa tim memilih untuk berpegang pada satu gaya penulisan (**default** atau **named**), atau menghindari mencampurnya dalam satu *file*. Lakukan yang terbaik untuk Anda!
157157

158158
</Note>
159159

160-
First, **export** `Profile` from `Gallery.js` using a named export (no `default` keyword):
160+
Pertama, **ekspor** `Profile` dari `Gallery.js` menggunakan **named exports** (tanpa kata kunci **default**):
161161

162162
```js
163163
export function Profile() {
164164
// ...
165165
}
166166
```
167167

168-
Then, **import** `Profile` from `Gallery.js` to `App.js` using a named import (with the curly braces):
168+
Selanjutnya, **impor** `Profile` dari `Gallery.js` ke `App.js` menggunakan **named imports** (dengan kurung kurawal):
169169

170170
```js
171171
import { Profile } from './Gallery.js';
172172
```
173173

174-
Finally, **render** `<Profile />` from the `App` component:
174+
Akhirnya, **render** `<Profile />` dari komponen `App`:
175175

176176
```js
177177
export default function App() {
178178
return <Profile />;
179179
}
180180
```
181181

182-
Now `Gallery.js` contains two exports: a default `Gallery` export, and a named `Profile` export. `App.js` imports both of them. Try editing `<Profile />` to `<Gallery />` and back in this example:
182+
Sekarang `Gallery.js` berisi dua ekspor: **default exports** `Gallery`, dan **named exports** `Profile`. `App.js` mengimpor keduanya.
183+
Coba mengedit `<Profile />` ke `<Gallery />` dan kembali pada contoh ini:
183184

184185
<Sandpack>
185186

@@ -207,7 +208,7 @@ export function Profile() {
207208
export default function Gallery() {
208209
return (
209210
<section>
210-
<h1>Amazing scientists</h1>
211+
<h1>Para ilmuwan hebat</h1>
211212
<Profile />
212213
<Profile />
213214
<Profile />
@@ -222,47 +223,47 @@ img { margin: 0 10px 10px 0; height: 90px; }
222223

223224
</Sandpack>
224225

225-
Now you're using a mix of default and named exports:
226+
Sekarang Anda menggunakan campuran **default** dan **named exports**:
226227

227228
* `Gallery.js`:
228-
- Exports the `Profile` component as a **named export called `Profile`.**
229-
- Exports the `Gallery` component as a **default export.**
229+
- Mengekspor komponen `Profile` sebagai **named exports bernama `Profile`.**
230+
- Mengekspor komponen `Gallery` sebagai **default exports.**
230231
* `App.js`:
231-
- Imports `Profile` as a **named import called `Profile`** from `Gallery.js`.
232-
- Imports `Gallery` as a **default import** from `Gallery.js`.
233-
- Exports the root `App` component as a **default export.**
232+
- Mengimpor `Profile` as a **named imports called `Profile`** dari `Gallery.js`.
233+
- Mengimpor `Gallery` as a **default imports** dari `Gallery.js`.
234+
- Mengekspor komponen root `App` sebagai **default exports.**
234235

235236
<Recap>
236237

237-
On this page you learned:
238+
Pada halaman ini Anda belajar:
238239

239-
* What a root component file is
240-
* How to import and export a component
241-
* When and how to use default and named imports and exports
242-
* How to export multiple components from the same file
240+
* Apa itu *file* komponen root
241+
* Bagaimana cara impor dan ekspor komponen
242+
* Kapan menggunakan **default** dan **named** impor dan ekspor
243+
* Bagaimana cara mengimpor dan mengekspor beberapa komponen pada satu *file*
243244

244245
</Recap>
245246

246247

247248

248249
<Challenges>
249250

250-
#### Split the components further {/*split-the-components-further*/}
251+
#### Memisahkan komponen lebih jauh {/*split-the-components-further*/}
251252

252-
Currently, `Gallery.js` exports both `Profile` and `Gallery`, which is a bit confusing.
253+
Saat ini, `Gallery.js` mengekspor kedua `Profile` dan `Gallery`, yang mana sedikit membingungkan.
253254

254-
Move the `Profile` component to its own `Profile.js`, and then change the `App` component to render both `<Profile />` and `<Gallery />` one after another.
255+
Pindahkan komponen `Profile` pada miliknya sendiri `Profile.js`, dan ubah komponen `App` untuk merender kedua `<Profile />` dan `<Gallery />` satu setelah lainnya.
255256

256-
You may use either a default or a named export for `Profile`, but make sure that you use the corresponding import syntax in both `App.js` and `Gallery.js`! You can refer to the table from the deep dive above:
257+
Anda mungkin menggukanan salah satu dari **default** atau **named** eskpor untuk `Profile`, tetapi pastikan bahwa Anda menggunakan sintaksis impor pada kedua `App.js` dan `Gallery.js`. Anda dapat merujuk pada table dari bagian **deep dive** di atas:
257258

258-
| Syntax | Export statement | Import statement |
259+
| Sintaksis | Pernyataan Expor | Pernyataan Impor |
259260
| ----------- | ----------- | ----------- |
260261
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
261262
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
262263

263264
<Hint>
264265

265-
Don't forget to import your components where they are called. Doesn't `Gallery` use `Profile`, too?
266+
Jangan lupa untuk mengimpor komponen Anda di mana mereka dipanggil. Bukankah `Gallery` juga menggunakan `Profile`?
266267

267268
</Hint>
268269

@@ -282,7 +283,7 @@ export default function App() {
282283
```
283284

284285
```js Gallery.js active
285-
// Move me to Profile.js!
286+
// Pindahkan saya ke Profile.js!
286287
export function Profile() {
287288
return (
288289
<img
@@ -295,7 +296,7 @@ export function Profile() {
295296
export default function Gallery() {
296297
return (
297298
<section>
298-
<h1>Amazing scientists</h1>
299+
<h1>Para ilmuwan hebat</h1>
299300
<Profile />
300301
<Profile />
301302
<Profile />
@@ -313,11 +314,11 @@ img { margin: 0 10px 10px 0; height: 90px; }
313314

314315
</Sandpack>
315316

316-
After you get it working with one kind of exports, make it work with the other kind.
317+
Setelah Anda berhasil menjalankan dengan salah satu ekspor, buat juga berjalan dengan jenis yang lain.
317318

318319
<Solution>
319320

320-
This is the solution with named exports:
321+
Ini adalah solusi menggunakan `named exports`:
321322

322323
<Sandpack>
323324

@@ -341,7 +342,7 @@ import { Profile } from './Profile.js';
341342
export default function Gallery() {
342343
return (
343344
<section>
344-
<h1>Amazing scientists</h1>
345+
<h1>Para ilmuwan hebat</h1>
345346
<Profile />
346347
<Profile />
347348
<Profile />
@@ -367,7 +368,7 @@ img { margin: 0 10px 10px 0; height: 90px; }
367368

368369
</Sandpack>
369370

370-
This is the solution with default exports:
371+
Ini adalah solusi menggunakan `default exports`:
371372

372373
<Sandpack>
373374

@@ -391,7 +392,7 @@ import Profile from './Profile.js';
391392
export default function Gallery() {
392393
return (
393394
<section>
394-
<h1>Amazing scientists</h1>
395+
<h1>Para ilmuwan hebat</h1>
395396
<Profile />
396397
<Profile />
397398
<Profile />

0 commit comments

Comments
 (0)