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
With`'use client'`, you can determine when components are Client Components. As Server Components are default, here is a brief overview of the advantages and limitations to Server Components to determine when you need to mark something as client rendered.
235
+
Dengan`'use client'`, Anda dapat menentukan kapan komponen merupakan Komponen Klien. Karena Komponen Server adalah komponen default, berikut adalah penjelasan singkat tentang kelebihan dan keterbatasan Komponen Server untuk menentukan kapan Anda perlu menandai sebuah komponen sebagai komponen yang dirender oleh klien.
236
236
237
-
For simplicity, we talk about Server Components, but the same principles apply to all code in your app that is server run.
237
+
Untuk menyederhanakannya, kita berbicara tentang Komponen Server, tetapi prinsip yang sama berlaku untuk semua kode di aplikasi Anda yang dijalankan oleh server.
238
238
239
-
#### Advantages of Server Components {/*advantages*/}
240
-
* Server Components can reduce the amount of code sent and run by the client. Only Client modules are bundled and evaluated by the client.
241
-
* Server Components benefit from running on the server. They can access the local filesystem and may experience low latency for data fetches and network requests.
239
+
#### Keuntungan Komponen Server {/*advantages*/}
240
+
*Komponen Server dapat mengurangi jumlah kode yang dikirim dan dijalankan oleh klien. Hanya modul Klien yang dibundel dan dievaluasi oleh klien.
241
+
*Komponen Server diuntungkan karena berjalan di server. Komponen tersebut dapat mengakses sistem berkas lokal dan mungkin mengalami latensi rendah untuk pengambilan data dan permintaan jaringan.
242
242
243
-
#### Limitations of Server Components {/*limitations*/}
244
-
* Server Components cannot support interaction as event handlers must be registered and triggered by a client.
245
-
* For example, event handlers like `onClick` can only be defined in Client Components.
246
-
* Server Components cannot use most Hooks.
247
-
* When Server Components are rendered, their output is essentially a list of components for the client to render. Server Components do not persist in memory after render and cannot have their own state.
243
+
#### Batasan Komponen Server {/*limitations*/}
244
+
*Komponen Server tidak dapat mendukung interaksi karena *event handler* harus didaftarkan dan dipicu oleh klien.
245
+
* Misalnya, *event handler* seperti `onClick` hanya dapat didefinisikan dalam Komponen Klien.
246
+
*Komponen Server tidak dapat menggunakan sebagian besar Hook.
247
+
* Saat Komponen Server dirender, outputnya pada dasarnya adalah daftar komponen untuk dirender oleh klien. Komponen Server tidak bertahan dalam memori setelah dirender dan tidak dapat memiliki *state*-nya sendiri.
248
248
249
-
### Serializable types returned by Server Components {/*serializable-types*/}
249
+
### Tipe data yang dapat diserialisasikan yang dikembalikan oleh Komponen Server {/*serializable-types*/}
250
250
251
-
As in any React app, parent components pass data to child components. As they are rendered in different environments, passing data from a Server Component to a Client Component requires extra consideration.
251
+
Seperti dalam aplikasi React apa pun, komponen induk meneruskan data ke komponen anak. Karena komponen tersebut dirender dalam lingkungan yang berbeda, meneruskan data dari Komponen Server ke Komponen Klien memerlukan pertimbangan ekstra.
252
252
253
-
Prop values passed from a Server Component to Client Component must be serializable.
253
+
Nilai properti yang diteruskan dari Komponen Server ke Komponen Klien harus dapat diserialisasikan.
* [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), only symbols registered in the global Symbol registry via [`Symbol.for`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
264
-
*Iterables containing serializable values
263
+
* [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), hanya simbol yang terdaftar di registri Symbol global melalui [`Symbol.for`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
264
+
*Iterabel yang berisi nilai yang dapat diserialkan
* [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) and [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
269
+
* [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) dan [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
*Plain [objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): those created with [object initializers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer), with serializable properties
272
-
*Functions that are [Server Functions](/reference/rsc/server-functions)
*[Objek](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) biasa: objek-objek yang dibuat dengan [inisialisasi objek](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer), dengan properti yang dapat diserialisasikan
272
+
*Fungsi yang merupakan [Fungsi Server](/reference/rsc/server-functions)
*[Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)that are not exported from client-marked modules or marked with[`'use server'`](/reference/rsc/use-server)
*Objects that are instances of any class (other than the built-ins mentioned) or objects with [a null prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
280
-
*Symbols not registered globally, ex. `Symbol('my new symbol')`
276
+
Perlu diperhatikan, tipe-tipe data tersebut tidak didukung:
277
+
*[Fungsi](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)yang tidak diekspor dari modul bertanda klien atau ditandai dengan[`'use server'`](/reference/rsc/use-server)
*Objek yang merupakan *instance* kelas mana pun (selain yang sudah disebutkan) atau objek dengan [prototipe null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
280
+
*Symbol yang tidak terdaftar secara global, mis. `Symbol('my new symbol')`
281
281
282
282
283
-
## Usage {/*usage*/}
283
+
## Penggunaan {/*usage*/}
284
284
285
-
### Building with interactivity and state {/*building-with-interactivity-and-state*/}
285
+
### Membuat komponen dengan interaktivitas dan *state* {/*building-with-interactivity-and-state*/}
As`Counter`requires both the `useState`Hook and event handlers to increment or decrement the value, this component must be a Client Component and will require a `'use client'`directive at the top.
310
+
Karena`Counter`memerlukan Hook `useState`dan *event handler* untuk menambah atau mengurangi nilai, komponen ini harus menjadi Komponen Klien dan akan memerlukan direktif `'use client'`di bagian atas.
311
311
312
-
In contrast, a component that renders UI without interaction will not need to be a Client Component.
312
+
Sebaliknya, komponen yang merender UI tanpa interaksi tidak perlu menjadi Komponen Klien.
313
313
314
314
```js
315
315
import { readFile } from'node:fs/promises';
@@ -321,9 +321,9 @@ export default async function CounterContainer() {
321
321
}
322
322
```
323
323
324
-
For example, `Counter`'s parent component, `CounterContainer`, does not require `'use client'`as it is not interactive and does not use state. In addition, `CounterContainer`must be a Server Component as it reads from the local file system on the server, which is possible only in a Server Component.
324
+
Misalnya, komponen induk `Counter`, `CounterContainer`, tidak memerlukan `'use client'`karena tidak interaktif dan tidak menggunakan *state*. Selain itu, `CounterContainer`harus menjadi Komponen Server karena komponen tersebut membaca dari sistem berkas lokal di server, yang hanya mungkin dilakukan di Komponen Server.
325
325
326
-
There are also components that don't use any server or client-only features and can be agnostic to where they render. In our earlier example, `FancyText`is one such component.
326
+
Ada juga komponen yang tidak menggunakan fitur khusus server atau klien dan dapat bersifat tidak peduli terhadap di mana komponen tersebut ditampilkan. Dalam contoh sebelumnya, `FancyText`adalah salah satu komponen tersebut.
327
327
328
328
```js
329
329
exportdefaultfunctionFancyText({title, text}) {
@@ -333,15 +333,15 @@ export default function FancyText({title, text}) {
333
333
}
334
334
```
335
335
336
-
In this case, we don't add the`'use client'` directive, resulting in `FancyText`'s _output_ (rather than its source code) to be sent to the browser when referenced from a Server Component. As demonstrated in the earlier Inspirations app example, `FancyText`is used as both a Server or Client Component, depending on where it is imported and used.
336
+
Dalam kasus ini, kita tidak menambahkan direktif`'use client'`, yang mengakibatkan _output_`FancyText` (bukan kode sumbernya) dikirim ke browser saat dirujuk dari Komponen Server. Seperti yang ditunjukkan dalam contoh aplikasi Inspirasi sebelumnya, `FancyText`digunakan sebagai Komponen Server atau Klien, tergantung di mana ia diimpor dan digunakan.
337
337
338
-
But if `FancyText`'s HTML output was large relative to its source code (including dependencies), it might be more efficient to force it to always be a Client Component. Components that return a long SVG path string are one case where it may be more efficient to force a component to be a Client Component.
338
+
Namun, jika output HTML `FancyText` lebih besar dibandingkan dengan kode sumbernya (termasuk dependensi), mungkin lebih efisien untuk memaksanya agar selalu menjadi Komponen Klien. Komponen yang mengembalikan string *path* SVG yang panjang adalah salah satu kasus di mana mungkin lebih efisien untuk memaksa komponen menjadi Komponen Klien.
339
339
340
-
### Using client APIs {/*using-client-apis*/}
340
+
### Menggunakan API klien {/*using-client-apis*/}
341
341
342
-
Your React app may use client-specific APIs, such as the browser's APIs for web storage, audio and video manipulation, and device hardware, among [others](https://developer.mozilla.org/en-US/docs/Web/API).
342
+
Aplikasi React Anda mungkin menggunakan API khusus klien, seperti API browser untuk penyimpanan web, manipulasi audio dan video, dan perangkat keras, di antara [lainnya](https://developer.mozilla.org/en-US/docs/Web/API).
343
343
344
-
In this example, the component uses [DOM APIs](https://developer.mozilla.org/en-US/docs/Glossary/DOM)to manipulate a[`canvas`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) element. Since those APIs are only available in the browser, it must be marked as a Client Component.
344
+
Dalam contoh ini, komponen menggunakan [API DOM](https://developer.mozilla.org/en-US/docs/Glossary/DOM)untuk memanipulasi elemen[`canvas`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas). Karena API tersebut hanya tersedia di browser, komponen tersebut harus ditandai sebagai Komponen Klien.
345
345
346
346
```js
347
347
'use client';
@@ -362,18 +362,18 @@ export default function Circle() {
362
362
}
363
363
```
364
364
365
-
### Using third-party libraries {/*using-third-party-libraries*/}
365
+
### Menggunakan pustaka pihak ketiga {/*using-third-party-libraries*/}
366
366
367
-
Often in a React app, you'll leverage third-party libraries to handle common UI patterns or logic.
367
+
Sering kali dalam aplikasi React, Anda akan memanfaatkan pustaka pihak ketiga untuk menangani pola atau logika UI umum.
368
368
369
-
These libraries may rely on component Hooks or client APIs. Third-party components that use any of the following React APIs must run on the client:
369
+
Pustaka ini dapat mengandalkan Hook komponen atau API klien. Komponen pihak ketiga yang menggunakan salah satu API React berikut harus berjalan pada klien:
*If they use client APIs, ex. DOM insertion or native platform views
375
+
*Jika menggunakan API klien, mis. penyisipan DOM atau *view* dari *platform native*
376
376
377
-
If these libraries have been updated to be compatible with React Server Components, then they will already include `'use client'`markers of their own, allowing you to use them directly from your Server Components. If a library hasn't been updated, or if a component needs props like event handlers that can only be specified on the client, you may need to add your own Client Component file in between the third-party Client Component and your Server Component where you'd like to use it.
377
+
Jika pustaka ini telah diperbarui agar kompatibel dengan Komponen Server React, maka pustaka tersebut akan menyertakan direktif `'use client'`sendiri, yang memungkinkan Anda untuk menggunakannya langsung dari Komponen Server Anda. Jika pustaka belum diperbarui, atau jika komponen memerlukan *props* seperti *event handler* yang hanya dapat ditentukan pada klien, Anda mungkin perlu menambahkan file Komponen Klien Anda sendiri di antara Komponen Klien pihak ketiga dan Komponen Server Anda di mana Anda ingin menggunakannya.
0 commit comments