-
Notifications
You must be signed in to change notification settings - Fork 266
docs: translate 'use server' #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,26 +6,26 @@ canary: true | |||||
|
|
||||||
| <Canary> | ||||||
|
|
||||||
| `'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. | ||||||
| `'use server'` hanya diperlukan jika Anda [menggunakan Komponen *React Server*](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) atau sedang membangun library yang kompatibel dengan fitur tersebut. | ||||||
|
|
||||||
| </Canary> | ||||||
|
|
||||||
|
|
||||||
| <Intro> | ||||||
|
|
||||||
| `'use server'` marks server-side functions that can be called from client-side code. | ||||||
| `'use server'` menandai fungsi-fungsi sisi server yang dapat dipanggil dari kode sisi klien. | ||||||
|
|
||||||
| </Intro> | ||||||
|
|
||||||
| <InlineToc /> | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## Reference {/*reference*/} | ||||||
| ## Referensi {/*reference*/} | ||||||
|
|
||||||
| ### `'use server'` {/*use-server*/} | ||||||
|
|
||||||
| 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_. | ||||||
| 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). | ||||||
|
|
||||||
| ```js {2} | ||||||
| async function addToCart(data) { | ||||||
|
|
@@ -34,77 +34,74 @@ async function addToCart(data) { | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| 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. | ||||||
| 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. | ||||||
|
|
||||||
| 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. | ||||||
| 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. | ||||||
|
|
||||||
| #### Caveats {/*caveats*/} | ||||||
| * `'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. | ||||||
| * `'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). | ||||||
| * To import a Server Action from [client code](/reference/rsc/use-client), the directive must be used on a module level. | ||||||
| * Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions. | ||||||
| * Always treat arguments to Server Actions as untrusted input and authorize any mutations. See [security considerations](#security). | ||||||
| * 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. | ||||||
| * 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. | ||||||
| #### Peringatan {/*caveats*/} | ||||||
| * Untuk mengimpor Aksi Server dari [kode klien](/reference/rsc/use-client), direktif harus digunakan pada level modul. | ||||||
| * Karena pemanggilan jaringan yang mendasarinya bersifat asinkron, `'use server'` hanya boleh digunakan pada fungsi asinkron. | ||||||
| * Selalu perlakukan argumen yang diterima Aksi Server sebagai input yang tidak terpercaya, dan pastikan semua perubahan (mutasi) telah diautorisasi. Lihat [pertimbangan keamanan](#security). | ||||||
| * 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. | ||||||
| * 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. | ||||||
|
|
||||||
| ### Security considerations {/*security*/} | ||||||
| ### Pertimbangan Keamanan {/*security*/} | ||||||
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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. | ||||||
| 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. | ||||||
|
|
||||||
| In any Server Action, make sure to validate that the logged-in user is allowed to perform that action. | ||||||
| Dalam setiap Aksi Server, pastikan untuk memvalidasi bahwa pengguna yang sedang masuk diizinkan untuk melakukan aksi tersebut. | ||||||
|
|
||||||
| <Wip> | ||||||
|
|
||||||
| 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. | ||||||
| Untuk mencegah pengiriman data sensitif dari Aksi Server, terdapat *API taint* eksperimental untuk mencegah nilai dan objek unik diteruskan ke kode klien. | ||||||
|
|
||||||
| See [experimental_taintUniqueValue](/reference/react/experimental_taintUniqueValue) and [experimental_taintObjectReference](/reference/react/experimental_taintObjectReference). | ||||||
| Lihat [*experimental_taintUniqueValue*](/reference/react/experimental_taintUniqueValue) dan [*experimental_taintObjectReference*](/reference/react/experimental_taintObjectReference). | ||||||
|
|
||||||
| </Wip> | ||||||
|
|
||||||
| ### Serializable arguments and return values {/*serializable-parameters-and-return-values*/} | ||||||
| ### Argumen yang dapat diserialisasi dan Nilai kembalian {/*serializable-parameters-and-return-values*/} | ||||||
|
||||||
| ### Argumen yang dapat diserialisasi dan Nilai kembalian {/*serializable-parameters-and-return-values*/} | |
| ### Argumen yang dapat diserialisasi dan nilai kembalian {/*serializable-parameters-and-return-values*/} |
Idem.
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| Untuk memperbarui antarmuka pengguna berdasarkan hasil dari Aksi Server sambil tetap mendukung peningkatan progresif gunakan [*`useActionState`*](/reference/react/useActionState). | |
| Untuk memperbarui antarmuka pengguna berdasarkan hasil dari Aksi Server sambil tetap mendukung peningkatan progresif gunakan [`useActionState`](/reference/react/useActionState). |
Idem.
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
resir014 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.