Skip to content

Commit 3c39a1b

Browse files
authored
docs: translate 'use server' (#755)
1 parent 468838c commit 3c39a1b

File tree

1 file changed

+67
-68
lines changed

1 file changed

+67
-68
lines changed

src/content/reference/rsc/use-server.md

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ canary: true
66

77
<Canary>
88

9-
`'use server'` is needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.
9+
`'use server'` hanya diperlukan jika Anda [menggunakan Komponen Server React](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) atau sedang membangun library yang kompatibel dengan fitur tersebut.
1010

1111
</Canary>
1212

1313

1414
<Intro>
1515

16-
`'use server'` marks server-side functions that can be called from client-side code.
16+
`'use server'` menandai fungsi-fungsi sisi server yang dapat dipanggil dari kode sisi klien.
1717

1818
</Intro>
1919

2020
<InlineToc />
2121

2222
---
2323

24-
## Reference {/*reference*/}
24+
## Referensi {/*reference*/}
2525

2626
### `'use server'` {/*use-server*/}
2727

28-
Add `'use server'` at the top of an async function body to mark the function as callable by the client. We call these functions _Server Actions_.
28+
Tambahkan `'use server'` di bagian atas fungsi async untuk menandai bahwa fungsi tersebut dapat dipanggil oleh klien. Kami menyebut fungsi-fungsi ini sebagai [Aksi Server](/reference/rsc/server-actions).
2929

3030
```js {2}
3131
async function addToCart(data) {
@@ -34,77 +34,74 @@ async function addToCart(data) {
3434
}
3535
```
3636

37-
When calling a Server Action on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the Server Action returns a value, that value will be serialized and returned to the client.
37+
Saat memanggil Aksi Server dari klien, `'use server'` akan melakukan permintaan jaringan *(network request)* ke server dan menyertakan salinan ter-serialisasi dari setiap argumen yang dikirim. Jika Aksi Server mengembalikan sebuah nilai, nilai tersebut akan di-serialisasi dan dikembalikan ke klien.
3838

39-
Instead of individually marking functions with `'use server'`, you can add the directive to the top of a file to mark all exports within that file as Server Actions that can be used anywhere, including imported in client code.
39+
Daripada menandai fungsi satu per satu dengan `'use server'`, Anda bisa menambahkan [Direktif](/reference/rsc/directives) ini di bagian paling atas *file* untuk menandai semua fungsi yang di ekspor dalam *file* tersebut sebagai Aksi Server nantinya semua fungsi yang di ekspor pada *file* tersebut bisa digunakan di mana saja, termasuk diimpor dalam kode klien.
4040

41-
#### Caveats {/*caveats*/}
42-
* `'use server'` must be at the very beginning of their function or module; above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks.
43-
* `'use server'` can only be used in server-side files. The resulting Server Actions can be passed to Client Components through props. See supported [types for serialization](#serializable-parameters-and-return-values).
44-
* To import a Server Action from [client code](/reference/rsc/use-client), the directive must be used on a module level.
45-
* Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions.
46-
* Always treat arguments to Server Actions as untrusted input and authorize any mutations. See [security considerations](#security).
47-
* Server Actions should be called in a [Transition](/reference/react/useTransition). Server Actions passed to [`<form action>`](/reference/react-dom/components/form#props) or [`formAction`](/reference/react-dom/components/input#props) will automatically be called in a transition.
48-
* Server Actions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Actions typically process one action at a time and do not have a way to cache the return value.
41+
#### Peringatan {/*caveats*/}
42+
* Untuk mengimpor Aksi Server dari [kode klien](/reference/rsc/use-client), direktif harus digunakan pada level modul.
43+
* Karena pemanggilan jaringan yang mendasarinya bersifat asinkron, `'use server'` hanya boleh digunakan pada fungsi asinkron.
44+
* Selalu perlakukan argumen yang diterima Aksi Server sebagai input yang tidak terpercaya, dan pastikan semua perubahan (mutasi) telah diautorisasi. Lihat [pertimbangan keamanan](#security).
45+
* Aksi Server sebaiknya dipanggil dalam sebuah [Transisi](/reference/react/useTransition). Aksi Server yang diteruskan ke [`<form action>`](/reference/react-dom/components/form#props) atau [`formAction`](/reference/react-dom/components/input#props) akan secara otomatis dipanggil dalam sebuah transisi.
46+
* Aksi Server dirancang untuk melakukan mutasi yang memperbarui data di sisi server; Sehingga Aksi Server tidak disarankan untuk pengambilan data. Oleh karena itu, *framework* yang mengimplementasikan Aksi Server umumnya memproses satu aksi dalam satu waktu dan tidak menyediakan mekanisme untuk melakukan *caching* terhadap nilai yang dikembalikan.
4947

50-
### Security considerations {/*security*/}
48+
### Pertimbangan keamanan {/*security*/}
5149

52-
Arguments to Server Actions are fully client-controlled. For security, always treat them as untrusted input, and make sure to validate and escape arguments as appropriate.
50+
Argumen untuk Aksi Server sepenuhnya dikendalikan oleh klien. Demi keamanan, selalu perlakukan argumen tersebut sebagai masukan yang tidak tepercaya, dan pastikan untuk memvalidasi serta menyaring argumen sesuai kebutuhan.
5351

54-
In any Server Action, make sure to validate that the logged-in user is allowed to perform that action.
52+
Dalam setiap Aksi Server, pastikan untuk memvalidasi bahwa pengguna yang sedang masuk diizinkan untuk melakukan aksi tersebut.
5553

5654
<Wip>
5755

58-
To prevent sending sensitive data from a Server Action, there are experimental taint APIs to prevent unique values and objects from being passed to client code.
56+
Untuk mencegah pengiriman data sensitif dari Aksi Server, terdapat *API taint* eksperimental untuk mencegah nilai dan objek unik diteruskan ke kode klien.
5957

60-
See [experimental_taintUniqueValue](/reference/react/experimental_taintUniqueValue) and [experimental_taintObjectReference](/reference/react/experimental_taintObjectReference).
58+
Lihat [*experimental_taintUniqueValue*](/reference/react/experimental_taintUniqueValue) dan [*experimental_taintObjectReference*](/reference/react/experimental_taintObjectReference).
6159

6260
</Wip>
6361

64-
### Serializable arguments and return values {/*serializable-parameters-and-return-values*/}
62+
### Argumen yang dapat diserialisasi dan nilai kembalian {/*serializable-parameters-and-return-values*/}
6563

66-
As client code calls the Server Action over the network, any arguments passed will need to be serializable.
64+
Karena kode klien memanggil Aksi Server melalui jaringan, setiap argumen yang dikirim harus dapat diserialisasi.
6765

68-
Here are supported types for Server Action arguments:
66+
Berikut adalah tipe data yang didukung untuk argumen Aksi Server:
6967

70-
* Primitives
71-
* [string](https://developer.mozilla.org/en-US/docs/Glossary/String)
72-
* [number](https://developer.mozilla.org/en-US/docs/Glossary/Number)
73-
* [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
74-
* [boolean](https://developer.mozilla.org/en-US/docs/Glossary/Boolean)
75-
* [undefined](https://developer.mozilla.org/en-US/docs/Glossary/Undefined)
76-
* [null](https://developer.mozilla.org/en-US/docs/Glossary/Null)
77-
* [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)
78-
* Iterables containing serializable values
79-
* [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
80-
* [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
81-
* [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
82-
* [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
83-
* [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)
84-
* [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
85-
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instances
86-
* 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
87-
* Functions that are Server Actions
88-
* [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
68+
* Primitif
69+
* [*string*](https://developer.mozilla.org/en-US/docs/Glossary/String)
70+
* [*number*](https://developer.mozilla.org/en-US/docs/Glossary/Number)
71+
* [*bigint*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
72+
* [*boolean*](https://developer.mozilla.org/en-US/docs/Glossary/Boolean)
73+
* [*undefined*](https://developer.mozilla.org/en-US/docs/Glossary/Undefined)
74+
* [*null*](https://developer.mozilla.org/en-US/docs/Glossary/Null)
75+
* [Simbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), hanya simbol yang didaftarkan dalam Registri Simbol Global melalui [`Symbol.for`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
76+
* *Iterable* yang berisi nilai yang dapat diserialkan
77+
* [*String*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
78+
* [Senarai](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
79+
* [*Map*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
80+
* [*Set*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
81+
* [*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)
82+
* [*Date*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
83+
* *Instance* [*FormData*](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
84+
* [Objek](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) biasa: objek yang dibuat dengan [*object initializers*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer), dengan properti yang dapat diserialisasi
85+
* Fungsi yang merupakan Aksi Server
86+
* [*Promises*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
8987

90-
Notably, these are not supported:
91-
* React elements, or [JSX](/learn/writing-markup-with-jsx)
92-
* Functions, including component functions or any other function that is not a Server Action
93-
* [Classes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Classes_in_JavaScript)
94-
* 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)
95-
* Symbols not registered globally, ex. `Symbol('my new symbol')`
88+
Yang tidak didukung, antara lain:
9689

90+
* Elemen React, atau [*JSX*](/learn/writing-markup-with-jsx)
91+
* Fungsi komponen atau fungsi lainnya yang bukan Aksi Server
92+
* [Kelas](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Classes_in_JavaScript)
93+
* [Objek](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) yang merupakan *instance* dari kelas apa pun (selain bawaan seperti yang telah disebutkan) atau objek dengan [*null prototype*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
94+
* Simbol yang tidak didaftarkan secara global, misalnya `Symbol('my new symbol')`
9795

98-
Supported serializable return values are the same as [serializable props](/reference/rsc/use-client#passing-props-from-server-to-client-components) for a boundary Client Component.
96+
Nilai kembali yang dapat diserialisasi mengikuti aturan yang sama dengan [properti yang bisa diserialisasi](/reference/rsc/use-client#passing-props-from-server-to-client-components) untuk Komponen Klien yang menjadi pembatas.
9997

98+
## Penggunaan {/*usage*/}
10099

101-
## Usage {/*usage*/}
100+
### Aksi Server dalam formulir {/*server-actions-in-forms*/}
102101

103-
### Server Actions in forms {/*server-actions-in-forms*/}
102+
Aksi Server biasanya digunakan untuk memanggil fungsi di server yang mengubah data. Di peramban, pengguna umumnya mengirimkan perubahan data lewat [elemen formulir HTML](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form). Dengan komponen server React, React kini mendukung Aksi Server secara langsung di dalam formulir.
104103

105-
The most common use case of Server Actions will be calling server functions that mutate data. On the browser, the [HTML form element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) is the traditional approach for a user to submit a mutation. With React Server Components, React introduces first-class support for Server Actions in [forms](/reference/react-dom/components/form).
106-
107-
Here is a form that allows a user to request a username.
104+
Contoh di bawah ini menunjukkan formulir yang meminta nama pengguna.
108105

109106
```js [[1, 3, "formData"]]
110107
// App.js
@@ -119,21 +116,23 @@ export default function App() {
119116
return (
120117
<form action={requestUsername}>
121118
<input type="text" name="username" />
122-
<button type="submit">Request</button>
119+
<button type="submit">Meminta</button>
123120
</form>
124121
);
125122
}
126123
```
127124

128-
In this example `requestUsername` is a Server Action passed to a `<form>`. When a user submits this form, there is a network request to the server function `requestUsername`. When calling a Server Action in a form, React will supply the form's <CodeStep step={1}>[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep> as the first argument to the Server Action.
125+
Dalam contoh ini, `requestUsername` adalah sebuah Aksi Server yang diteruskan ke sebuah formulir `<form>.`
126+
Ketika pengguna mengirim formulir ini, akan ada permintaan jaringan ke fungsi server `requestUsername`.
127+
Saat memanggil Aksi Server lewat formulir, React akan mengirimkan <CodeStep step={1}>[*FormData*](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep> dari formulir sebagai argumen pertama ke Aksi Server tersebut.
129128

130-
By passing a Server Action to the form `action`, React can [progressively enhance](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement) the form. This means that forms can be submitted before the JavaScript bundle is loaded.
129+
Dengan meneruskan Aksi Server ke `action` formulir, React bisa meningkatkan fungsionalitas formulir secara [progresif](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). Artinya, formulir tetap bisa dikirimkan meskipun bundel *JavaScript* belum dimuat sepenuhnya.
131130

132-
#### Handling return values in forms {/*handling-return-values*/}
131+
#### Menangani nilai kembali dari formulir {/*handling-return-values*/}
133132

134-
In the username request form, there might be the chance that a username is not available. `requestUsername` should tell us if it fails or not.
133+
Dalam formulir diatas, ada kemungkinan nama pengguna yang diminta tidak tersedia. `requestUsername` harus memberi tahu apakah permintaan tersebut berhasil atau gagal.
135134

136-
To update the UI based on the result of a Server Action while supporting progressive enhancement, use [`useActionState`](/reference/react/useActionState).
135+
Untuk memperbarui antarmuka pengguna berdasarkan hasil dari Aksi Server sambil tetap mendukung peningkatan progresif gunakan [`useActionState`](/reference/react/useActionState).
137136

138137
```js
139138
// requestUsername.js
@@ -163,21 +162,21 @@ function UsernameForm() {
163162
<>
164163
<form action={action}>
165164
<input type="text" name="username" />
166-
<button type="submit">Request</button>
165+
<button type="submit">Meminta</button>
167166
</form>
168-
<p>Last submission request returned: {state}</p>
167+
<p>Respon dari pengiriman terakhir: {state}</p>
169168
</>
170169
);
171170
}
172171
```
173172

174-
Note that like most Hooks, `useActionState` can only be called in <CodeStep step={1}>[client code](/reference/rsc/use-client)</CodeStep>.
173+
Perlu diingat bahwa seperti Hook lainnya, `useActionState` hanya bisa dipanggil di <CodeStep step={1}>[kode klien](/reference/rsc/use-client)</CodeStep>.
175174

176-
### Calling a Server Action outside of `<form>` {/*calling-a-server-action-outside-of-form*/}
175+
### Memanggil sebuah Aksi Server dari luar formulir `<form>` {/*calling-a-server-action-outside-of-form*/}
177176

178-
Server Actions are exposed server endpoints and can be called anywhere in client code.
177+
Aksi Server adalah *endpoint* di sisi server dan bisa dipanggil dari mana saja di dalam kode klien.
179178

180-
When using a Server Action outside of a [form](/reference/react-dom/components/form), call the Server Action in a [Transition](/reference/react/useTransition), which allows you to display a loading indicator, show [optimistic state updates](/reference/react/useOptimistic), and handle unexpected errors. Forms will automatically wrap Server Actions in transitions.
179+
Jika Anda menggunakan Aksi server di luar [formulir](/reference/react-dom/components/form), panggillah fungsi tersebut di dalam sebuah [Transisi](/reference/react/useTransition). Dengan begitu, Anda bisa menampilkan indikator pemuatan, melakukan [pembaruan status optimistis](/reference/react/useOptimistic), dan menangani error yang tidak terduga. Formulir akan secara otomatis membungkus Aksi Server di dalam transisi.
181180

182181
```js {9-12}
183182
import incrementLike from './actions';
@@ -196,8 +195,8 @@ function LikeButton() {
196195

197196
return (
198197
<>
199-
<p>Total Likes: {likeCount}</p>
200-
<button onClick={onClick} disabled={isPending}>Like</button>;
198+
<p>Total Suka: {likeCount}</p>
199+
<button onClick={onClick} disabled={isPending}>Suka</button>;
201200
</>
202201
);
203202
}
@@ -214,4 +213,4 @@ export default async function incrementLike() {
214213
}
215214
```
216215

217-
To read a Server Action return value, you'll need to `await` the promise returned.
216+
Untuk mendapatkan hasil dari Aksi Server, Anda perlu menunggu *promise*-nya dengan menggunakan *await*.

0 commit comments

Comments
 (0)