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
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-components.md
+54-52Lines changed: 54 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,42 @@
1
1
---
2
-
title: React Server Components
2
+
title: "Komponen Server React"
3
3
canary: true
4
4
---
5
5
6
6
<Intro>
7
7
8
-
Server Components are a new type of Component that renders ahead of time, before bundling, in an environment separate from your client app or SSR server.
8
+
Komponen Server adalah jenis Komponen baru yang dirender terlebih dahulu, sebelum proses bundling, di lingkungan yang terpisah dari aplikasi klien atau server SSR Anda.
9
+
9
10
10
11
</Intro>
11
12
12
-
This separate environment is the "server" in React Server Components. Server Components can run once at build time on your CI server, or they can be run for each request using a web server.
13
+
Lingkungan terpisah ini adalah "server" dalam Komponen Server React. Komponen Server dapat dijalankan sekali saat build di server CI Anda, atau dapat dijalankan untuk setiap permintaan menggunakan web server.
13
14
14
15
<InlineToc />
15
16
16
17
<Note>
17
18
18
-
#### How do I build support for Server Components? {/*how-do-i-build-support-for-server-components*/}
19
19
20
-
While React Server Components in React 19 are stable and will not break between major versions, the underlying APIs used to implement a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x.
20
+
#### Bagaimana cara membangun dukungan untuk Komponen Server? {/*how-do-i-build-support-for-server-components*/}
21
+
22
+
Meskipun Komponen Server React di React 19 sudah stabil dan tidak akan rusak antar versi mayor, API dasar yang digunakan untuk mengimplementasikan bundler atau framework Komponen Server React tidak mengikuti semver dan dapat berubah antar versi minor di React 19.x.
21
23
22
-
To support React Server Components as a bundler or framework, we recommend pinning to a specific React version, or using the Canary release. We will continue working with bundlers and frameworks to stabilize the APIs used to implement React Server Components in the future.
24
+
Untuk mendukung Komponen Server React sebagai bundler atau framework, kami merekomendasikan untuk mengunci ke versi React tertentu, atau menggunakan rilis Canary. Kami akan terus bekerja sama dengan bundler dan framework untuk menstabilkan API yang digunakan untuk mengimplementasikan Komponen Server React di masa mendatang.
23
25
24
26
</Note>
25
27
26
-
### Server Components without a Server {/*server-components-without-a-server*/}
27
-
Server components can run at build time to read from the filesystem or fetch static content, so a web server is not required. For example, you may want to read static data from a content management system.
28
+
### Komponen Server tanpa Server {/*server-components-without-a-server*/}
29
+
Komponen server dapat dijalankan saat proses build untuk membaca dari filesystem atau mengambil konten statis, sehingga web server tidak diperlukan. Sebagai contoh, Anda mungkin ingin membaca data statis dari sistem manajemen konten.
28
30
29
-
Without Server Components, it's common to fetch static data on the client with an Effect:
31
+
Tanpa Komponen Server, biasanya data statis diambil di klien menggunakan Effect:
This pattern means users need to download and parse an additional 75K (gzipped) of libraries, and wait for a second request to fetch the data after the page loads, just to render static content that will not change for the lifetime of the page.
58
+
Pola ini berarti pengguna perlu mengunduh dan mengurai tambahan pustaka sebesar 75K (gzipped), dan menunggu permintaan kedua untuk mengambil data setelah halaman dimuat, hanya untuk merender konten statis yang tidak akan berubah selama masa hidup halaman.
57
59
58
-
With Server Components, you can render these components once at build time:
60
+
Dengan Komponen Server, Anda dapat merender komponen ini sekali saat proses build:
59
61
60
62
```js
61
-
importmarkedfrom'marked'; //Not included in bundle
62
-
importsanitizeHtmlfrom'sanitize-html'; //Not included in bundle
63
+
importmarkedfrom'marked'; //Tidak termasuk dalam bundel
64
+
importsanitizeHtmlfrom'sanitize-html'; //Tidak termasuk dalam bundel
63
65
64
66
asyncfunctionPage({page}) {
65
-
//NOTE: loads *during* render, when the app is built.
67
+
//CATATAN: dimuat *saat* render, ketika aplikasi dibangun.
66
68
constcontent=awaitfile.readFile(`${page}.md`);
67
69
68
70
return<div>{sanitizeHtml(marked(content))}</div>;
69
71
}
70
72
```
71
73
72
-
The rendered output can then be server-side rendered (SSR) to HTML and uploaded to a CDN. When the app loads, the client will not see the original `Page`component, or the expensive libraries for rendering the markdown. The client will only see the rendered output:
74
+
Output yang dirender kemudian dapat dirender di sisi server (SSR) ke HTML dan diunggah ke CDN. Ketika aplikasi dimuat, klien tidak akan melihat komponen `Page`yang asli, atau pustaka mahal untuk merender markdown. Klien hanya akan melihat output yang dirender:
73
75
74
76
```js
75
77
<div><!-- html for markdown --></div>
76
78
```
77
79
78
-
This means the content is visible during first page load, and the bundle does not include the expensive libraries needed to render the static content.
80
+
Ini berarti konten terlihat selama pemuatan halaman pertama, dan bundel tidak menyertakan pustaka mahal yang diperlukan untuk merender konten statis.
79
81
80
82
<Note>
81
83
82
-
You may notice that the Server Component above is an async function:
84
+
Anda mungkin memperhatikan bahwa Komponen Server di atas adalah fungsi async:
83
85
84
86
```js
85
87
asyncfunctionPage({page}) {
86
88
//...
87
89
}
88
90
```
89
91
90
-
Async Components are a new feature of Server Components that allow you to `await`in render.
92
+
Komponen Async adalah fitur baru dari Komponen Server yang memungkinkan Anda untuk `await`saat merender.
91
93
92
-
See [Async components with Server Components](#async-components-with-server-components)below.
94
+
Lihat [Komponen Async dengan Komponen Server](#async-components-with-server-components)di bawah ini.
93
95
94
96
</Note>
95
97
96
-
### Server Components with a Server {/*server-components-with-a-server*/}
97
-
Server Components can also run on a web server during a request for a page, letting you access your data layer without having to build an API. They are rendered before your application is bundled, and can pass data and JSX as props to Client Components.
98
+
### Komponen Server dengan Server {/*server-components-with-a-server*/}
99
+
Komponen Server juga dapat dijalankan di web server saat ada permintaan untuk sebuah halaman, sehingga Anda dapat mengakses data secara langsung tanpa perlu membangun API. Komponen ini dirender sebelum aplikasi Anda dibundel, dan dapat meneruskan data serta JSX sebagai props ke Komponen Klien.
98
100
99
-
Without Server Components, it's common to fetch dynamic data on the client in an Effect:
101
+
Tanpa Komponen Server, biasanya data dinamis diambil di klien menggunakan Effect:
With Server Components, you can read the data and render it in the component:
150
+
Dengan Komponen Server, Anda dapat membaca data dan merendernya langsung di komponen:
149
151
150
152
```js
151
153
importdbfrom'./database';
152
154
153
155
asyncfunctionNote({id}) {
154
-
//NOTE: loads *during* render.
156
+
//CATATAN: dimuat *saat* render.
155
157
constnote=awaitdb.notes.get(id);
156
158
return (
157
159
<div>
@@ -162,14 +164,14 @@ async function Note({id}) {
162
164
}
163
165
164
166
asyncfunctionAuthor({id}) {
165
-
//NOTE: loads *after* Note,
166
-
//but is fast if data is co-located.
167
+
//CATATAN: dimuat *setelah* Note,
168
+
//tapi akan cepat jika data berdekatan.
167
169
constauthor=awaitdb.authors.get(id);
168
170
return<span>By: {author.name}</span>;
169
171
}
170
172
```
171
173
172
-
The bundler then combines the data, rendered Server Components and dynamic Client Components into a bundle. Optionally, that bundle can then be server-side rendered (SSR) to create the initial HTML for the page. When the page loads, the browser does not see the original `Note`and`Author`components; only the rendered output is sent to the client:
174
+
Bundler kemudian akan menggabungkan data, Komponen Server yang sudah dirender, dan Komponen Klien dinamis ke dalam satu bundel. Opsional, bundel ini bisa dirender di sisi server(SSR) untuk membuat HTML awal halaman. Saat halaman dimuat, browser tidak akan melihat komponen `Note`dan`Author`asli; hanya output yang sudah dirender yang dikirim ke klien:
173
175
174
176
```js
175
177
<div>
@@ -178,26 +180,26 @@ The bundler then combines the data, rendered Server Components and dynamic Clien
178
180
</div>
179
181
```
180
182
181
-
Server Components can be made dynamic by re-fetching them from a server, where they can access the data and render again. This new application architecture combines the simple “request/response” mental model of server-centric Multi-Page Apps with the seamless interactivity of client-centric Single-Page Apps, giving you the best of both worlds.
183
+
Komponen Server dapat dibuat dinamis dengan mengambil ulang dari server, sehingga dapat mengakses data dan merender ulang. Arsitektur aplikasi baru ini menggabungkan model mental “request/response” sederhana dari Multi-Page Apps berbasis server dengan interaktivitas mulus dari Single-Page Apps berbasis klien, memberikan Anda keunggulan dari kedua dunia.
182
184
183
-
### Adding interactivity to Server Components {/*adding-interactivity-to-server-components*/}
185
+
### Menambahkan interaktivitas ke Komponen Server {/*adding-interactivity-to-server-components*/}
184
186
185
-
Server Components are not sent to the browser, so they cannot use interactive APIs like `useState`. To add interactivity to Server Components, you can compose them with Client Component using the `"use client"` directive.
187
+
Komponen Server tidak dikirim ke browser, jadi mereka tidak dapat menggunakan API interaktif seperti `useState`. Untuk menambahkan interaktivitas ke Komponen Server, Anda dapat menggabungkannya dengan Komponen Klien menggunakan direktif `"use client"`.
186
188
187
189
<Note>
188
190
189
-
#### There is no directive for Server Components. {/*there-is-no-directive-for-server-components*/}
191
+
#### Tidak ada direktif untuk Komponen Server. {/*there-is-no-directive-for-server-components*/}
190
192
191
-
A common misunderstanding is that Server Components are denoted by `"use server"`, but there is no directive for Server Components. The`"use server"`directive is used for Server Actions.
193
+
Sebuah kesalahpahaman umum adalah bahwa Komponen Server ditandai dengan `"use server"`, tetapi tidak ada direktif untuk Komponen Server. Direktif`"use server"`digunakan untuk Server Actions.
192
194
193
-
For more info, see the docs for[Directives](/reference/rsc/directives).
195
+
Untuk info lebih lanjut, lihat dokumen untuk[Directives](/reference/rsc/directives).
194
196
195
197
</Note>
196
198
197
199
198
-
In the following example, the `Notes`Server Component imports an `Expandable`Client Component that uses state to toggle its`expanded` state:
200
+
Dalam contoh berikut, Komponen Server `Notes`mengimpor Komponen Klien `Expandable`yang menggunakan state untuk mengubah status`expanded`:
199
201
```js
200
-
//Server Component
202
+
//Komponen Server
201
203
importExpandablefrom'./Expandable';
202
204
203
205
asyncfunctionNotes() {
@@ -214,7 +216,7 @@ async function Notes() {
214
216
}
215
217
```
216
218
```js
217
-
//Client Component
219
+
//Komponen Klien
218
220
"use client"
219
221
220
222
exportdefaultfunctionExpandable({children}) {
@@ -232,7 +234,7 @@ export default function Expandable({children}) {
232
234
}
233
235
```
234
236
235
-
This works by first rendering`Notes`as a Server Component, and then instructing the bundler to create a bundle for the Client Component `Expandable`. In the browser, the Client Components will see output of the Server Components passed as props:
237
+
Ini bekerja dengan pertama-tama merender`Notes`sebagai Komponen Server, dan kemudian menginstruksikan bundler untuk membuat bundel untuk Komponen Klien `Expandable`. Di browser, Komponen Klien akan melihat output dari Komponen Server yang diteruskan sebagai props:
236
238
237
239
```js
238
240
<head>
@@ -252,21 +254,21 @@ This works by first rendering `Notes` as a Server Component, and then instructin
252
254
</body>
253
255
```
254
256
255
-
### Async components with Server Components {/*async-components-with-server-components*/}
257
+
### Komponen Async dengan Komponen Server {/*async-components-with-server-components*/}
256
258
257
-
Server Components introduce a new way to write Components using async/await. When you`await`in an async component, React will suspend and wait for the promise to resolve before resuming rendering. This works across server/client boundaries with streaming support for Suspense.
259
+
Komponen Server memperkenalkan cara baru untuk menulis Komponen menggunakan async/await. Ketika Anda`await`di dalam komponen async, React akan suspend dan menunggu promise untuk diselesaikan sebelum melanjutkan rendering. Ini bekerja di seluruh batas server/klien dengan dukungan streaming untuk Suspense.
258
260
259
-
You can even create a promise on the server, and await it on the client:
261
+
Anda bahkan dapat membuat promise di server, dan menunggunya di klien:
260
262
261
263
```js
262
-
//Server Component
264
+
//Komponen Server
263
265
importdbfrom'./database';
264
266
265
267
asyncfunctionPage({id}) {
266
-
//Will suspend the Server Component.
268
+
//Akan suspend Komponen Server.
267
269
constnote=awaitdb.notes.get(id);
268
270
269
-
//NOTE: not awaited, will start here and await on the client.
271
+
//CATATAN: tidak ditunggu, akan mulai di sini dan menunggu di klien.
270
272
constcommentsPromise=db.comments.get(note.id);
271
273
return (
272
274
<div>
@@ -280,18 +282,18 @@ async function Page({id}) {
280
282
```
281
283
282
284
```js
283
-
//Client Component
285
+
//Komponen Klien
284
286
"use client";
285
287
import {use} from'react';
286
288
287
289
functionComments({commentsPromise}) {
288
-
//NOTE: this will resume the promise from the server.
289
-
//It will suspend until the data is available.
290
+
//CATATAN: ini akan melanjutkan promise dari server.
291
+
//Ini akan suspend sampai data tersedia.
290
292
constcomments=use(commentsPromise);
291
293
returncomments.map(commment=><p>{comment}</p>);
292
294
}
293
295
```
294
296
295
-
The`note`content is important data for the page to render, so we`await`it on the server. The comments are below the fold and lower-priority, so we start the promise on the server, and wait for it on the client with the `use`API. This will Suspend on the client, without blocking the`note`content from rendering.
297
+
Konten`note`adalah data penting untuk merender halaman, jadi kami`await`di server. Komentar berada di bawah lipatan dan memiliki prioritas lebih rendah, jadi kami memulai promise di server, dan menunggunya di klien dengan API `use`tersebut. Ini akan Suspend di klien, tanpa memblokir konten`note`untuk dirender.
296
298
297
-
Since async components are [not supported on the client](#why-cant-i-use-async-components-on-the-client), we await the promise with`use`.
299
+
Karena komponen async [tidak didukung di klien](#why-cant-i-use-async-components-on-the-client), kami menunggu promise dengan`use`.
0 commit comments