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
+55-53Lines changed: 55 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,47 @@
1
1
---
2
-
title: Server Components
2
+
title: "Komponen Server"
3
3
---
4
4
5
5
<RSC>
6
6
7
-
Server Components are for use in [React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
7
+
Komponen Server digunakan di [Komponen Server React](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
8
8
9
9
</RSC>
10
10
11
11
<Intro>
12
12
13
-
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.
13
+
Komponen Server adalah jenis Komponen baru yang dirender terlebih dahulu, sebelum proses bundling, di lingkungan yang terpisah dari aplikasi klien atau server SSR Anda.
14
+
14
15
15
16
</Intro>
16
17
17
-
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.
18
+
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.
18
19
19
20
<InlineToc />
20
21
21
22
<Note>
22
23
23
-
#### How do I build support for Server Components? {/*how-do-i-build-support-for-server-components*/}
24
24
25
-
While React Server Components in React 19 are stable and will not break between minor 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.
25
+
#### Bagaimana cara membangun dukungan untuk Komponen Server? {/*how-do-i-build-support-for-server-components*/}
26
+
27
+
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.
26
28
27
-
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.
29
+
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.
28
30
29
31
</Note>
30
32
31
-
### Server Components without a Server {/*server-components-without-a-server*/}
32
-
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.
33
+
### Komponen Server tanpa Server {/*server-components-without-a-server*/}
34
+
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.
33
35
34
-
Without Server Components, it's common to fetch static data on the client with an Effect:
36
+
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.
63
+
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.
62
64
63
-
With Server Components, you can render these components once at build time:
65
+
Dengan Komponen Server, Anda dapat merender komponen ini sekali saat proses build:
64
66
65
67
```js
66
-
importmarkedfrom'marked'; //Not included in bundle
67
-
importsanitizeHtmlfrom'sanitize-html'; //Not included in bundle
68
+
importmarkedfrom'marked'; //Tidak termasuk dalam bundel
69
+
importsanitizeHtmlfrom'sanitize-html'; //Tidak termasuk dalam bundel
68
70
69
71
asyncfunctionPage({page}) {
70
-
//NOTE: loads *during* render, when the app is built.
72
+
//CATATAN: dimuat *saat* render, ketika aplikasi dibangun.
71
73
constcontent=awaitfile.readFile(`${page}.md`);
72
74
73
75
return<div>{sanitizeHtml(marked(content))}</div>;
74
76
}
75
77
```
76
78
77
-
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:
79
+
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:
78
80
79
81
```js
80
82
<div><!-- html for markdown --></div>
81
83
```
82
84
83
-
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.
85
+
Ini berarti konten terlihat selama pemuatan halaman pertama, dan bundel tidak menyertakan pustaka mahal yang diperlukan untuk merender konten statis.
84
86
85
87
<Note>
86
88
87
-
You may notice that the Server Component above is an async function:
89
+
Anda mungkin memperhatikan bahwa Komponen Server di atas adalah fungsi async:
88
90
89
91
```js
90
92
asyncfunctionPage({page}) {
91
93
//...
92
94
}
93
95
```
94
96
95
-
Async Components are a new feature of Server Components that allow you to `await`in render.
97
+
Komponen Async adalah fitur baru dari Komponen Server yang memungkinkan Anda untuk `await`saat merender.
96
98
97
-
See [Async components with Server Components](#async-components-with-server-components)below.
99
+
Lihat [Komponen Async dengan Komponen Server](#async-components-with-server-components)di bawah ini.
98
100
99
101
</Note>
100
102
101
-
### Server Components with a Server {/*server-components-with-a-server*/}
102
-
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.
103
+
### Komponen Server dengan Server {/*server-components-with-a-server*/}
104
+
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.
103
105
104
-
Without Server Components, it's common to fetch dynamic data on the client in an Effect:
106
+
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:
155
+
Dengan Komponen Server, Anda dapat membaca data dan merendernya langsung di komponen:
154
156
155
157
```js
156
158
importdbfrom'./database';
157
159
158
160
asyncfunctionNote({id}) {
159
-
//NOTE: loads *during* render.
161
+
//CATATAN: dimuat *saat* render.
160
162
constnote=awaitdb.notes.get(id);
161
163
return (
162
164
<div>
@@ -167,14 +169,14 @@ async function Note({id}) {
167
169
}
168
170
169
171
asyncfunctionAuthor({id}) {
170
-
//NOTE: loads *after* Note,
171
-
//but is fast if data is co-located.
172
+
//CATATAN: dimuat *setelah* Note,
173
+
//tapi akan cepat jika data berdekatan.
172
174
constauthor=awaitdb.authors.get(id);
173
175
return<span>By: {author.name}</span>;
174
176
}
175
177
```
176
178
177
-
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:
179
+
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:
178
180
179
181
```js
180
182
<div>
@@ -183,26 +185,26 @@ The bundler then combines the data, rendered Server Components and dynamic Clien
183
185
</div>
184
186
```
185
187
186
-
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.
188
+
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.
187
189
188
-
### Adding interactivity to Server Components {/*adding-interactivity-to-server-components*/}
190
+
### Menambahkan interaktivitas ke Komponen Server {/*adding-interactivity-to-server-components*/}
189
191
190
-
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.
192
+
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"`.
191
193
192
194
<Note>
193
195
194
-
#### There is no directive for Server Components. {/*there-is-no-directive-for-server-components*/}
196
+
#### Tidak ada direktif untuk Komponen Server. {/*there-is-no-directive-for-server-components*/}
195
197
196
-
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 Functions.
198
+
Sebuah kesalahpahaman umum adalah bahwa Komponen Server ditandai dengan `"use server"`, tetapi tidak ada direktif untuk Komponen Server. Direktif`"use server"`digunakan untuk Fungsi Server.
197
199
198
-
For more info, see the docs for[Directives](/reference/rsc/directives).
200
+
Untuk info lebih lanjut, lihat dokumen untuk[Directives](/reference/rsc/directives).
199
201
200
202
</Note>
201
203
202
204
203
-
In the following example, the `Notes`Server Component imports an `Expandable`Client Component that uses state to toggle its`expanded` state:
205
+
Dalam contoh berikut, Komponen Server `Notes`mengimpor Komponen Klien `Expandable`yang menggunakan state untuk mengubah status`expanded`:
204
206
```js
205
-
//Server Component
207
+
//Komponen Server
206
208
importExpandablefrom'./Expandable';
207
209
208
210
asyncfunctionNotes() {
@@ -219,7 +221,7 @@ async function Notes() {
219
221
}
220
222
```
221
223
```js
222
-
//Client Component
224
+
//Komponen Klien
223
225
"use client"
224
226
225
227
exportdefaultfunctionExpandable({children}) {
@@ -237,7 +239,7 @@ export default function Expandable({children}) {
237
239
}
238
240
```
239
241
240
-
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:
242
+
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:
241
243
242
244
```js
243
245
<head>
@@ -257,21 +259,21 @@ This works by first rendering `Notes` as a Server Component, and then instructin
257
259
</body>
258
260
```
259
261
260
-
### Async components with Server Components {/*async-components-with-server-components*/}
262
+
### Komponen Async dengan Komponen Server {/*async-components-with-server-components*/}
261
263
262
-
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.
264
+
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.
263
265
264
-
You can even create a promise on the server, and await it on the client:
266
+
Anda bahkan dapat membuat promise di server, dan menunggunya di klien:
265
267
266
268
```js
267
-
//Server Component
269
+
//Komponen Server
268
270
importdbfrom'./database';
269
271
270
272
asyncfunctionPage({id}) {
271
-
//Will suspend the Server Component.
273
+
//Akan suspend Komponen Server.
272
274
constnote=awaitdb.notes.get(id);
273
275
274
-
//NOTE: not awaited, will start here and await on the client.
276
+
//CATATAN: tidak ditunggu, akan mulai di sini dan menunggu di klien.
275
277
constcommentsPromise=db.comments.get(note.id);
276
278
return (
277
279
<div>
@@ -285,18 +287,18 @@ async function Page({id}) {
285
287
```
286
288
287
289
```js
288
-
//Client Component
290
+
//Komponen Klien
289
291
"use client";
290
292
import {use} from'react';
291
293
292
294
functionComments({commentsPromise}) {
293
-
//NOTE: this will resume the promise from the server.
294
-
//It will suspend until the data is available.
295
+
//CATATAN: ini akan melanjutkan promise dari server.
296
+
//Ini akan suspend sampai data tersedia.
295
297
constcomments=use(commentsPromise);
296
298
returncomments.map(commment=><p>{comment}</p>);
297
299
}
298
300
```
299
301
300
-
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.
302
+
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.
301
303
302
-
Since async components are not supported on the client, we await the promise with`use`.
304
+
Karena komponen async tidak didukung di klien, kita menunggu promise dengan`use`.
0 commit comments