From fa62c925b8f4e78cb5b08527a5c0b23a27901362 Mon Sep 17 00:00:00 2001 From: Nizav Date: Wed, 14 May 2025 22:09:49 +0700 Subject: [PATCH] docs: translate form.md --- .../reference/react-dom/components/form.md | 122 +++++++++--------- 1 file changed, 60 insertions(+), 62 deletions(-) diff --git a/src/content/reference/react-dom/components/form.md b/src/content/reference/react-dom/components/form.md index 8f6ab00e0..cbe8c5e4e 100644 --- a/src/content/reference/react-dom/components/form.md +++ b/src/content/reference/react-dom/components/form.md @@ -5,19 +5,19 @@ canary: true -React's extensions to `
` are currently only available in React's canary and experimental channels. In stable releases of React, `` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components). Learn more about [React's release channels here](/community/versioning-policy#all-release-channels). +Ekstensi React untuk `` saat ini hanya tersedia di kanal *canary* dan eksperimental React. Pada rilis stabil React, `` hanya berfungsi sebagai [komponen HTML bawaan peramban](https://react.dev/reference/react-dom/components#all-html-components). Pelajari lebih lanjut tentang [kanal rilis React di sini](/community/versioning-policy#all-release-channels). -The [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) lets you create interactive controls for submitting information. +[Komponen `` bawaan peramban](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) memungkinkan Anda membuat kontrol interaktif untuk mengirimkan informasi. ```js - + ``` @@ -27,38 +27,38 @@ The [built-in browser `
` component](https://developer.mozilla.org/en-US/do --- -## Reference {/*reference*/} +## Referensi {/*reference*/} ### `` {/*form*/} -To create interactive controls for submitting information, render the [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form). +Untuk membuat kontrol interaktif untuk mengirimkan informasi, render [komponen `` bawaan peramban](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form). ```js - +
``` -[See more examples below.](#usage) +[Lihat contoh lainnya di bawah.](#usage) #### Props {/*props*/} -`
` supports all [common element props.](/reference/react-dom/components/common#props) +`` mendukung semua [props elemen umum.](/reference/react-dom/components/common#props) -[`action`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action): a URL or function. When a URL is passed to `action` the form will behave like the HTML form component. When a function is passed to `action` the function will handle the form submission. The function passed to `action` may be async and will be called with a single argument containing the [form data](https://developer.mozilla.org/en-US/docs/Web/API/FormData) of the submitted form. The `action` prop can be overridden by a `formAction` attribute on a ` +
); } @@ -91,13 +91,13 @@ export default function Search() { -### Handle form submission with a Server Action {/*handle-form-submission-with-a-server-action*/} +### Menangani pengiriman formulir dengan Server Action {/*handle-form-submission-with-a-server-action*/} -Render a `
` with an input and submit button. Pass a Server Action (a function marked with [`'use server'`](/reference/rsc/use-server)) to the `action` prop of form to run the function when the form is submitted. +Render sebuah `` dengan input dan tombol kirim. Lepaskan Server Action (sebuah fungsi yang ditandai dengan [`'use server'`](/reference/rsc/use-server)) ke prop `action` dari formulir untuk menjalankan fungsi tersebut saat formulir disubmit. -Passing a Server Action to `` allow users to submit forms without JavaScript enabled or before the code has loaded. This is beneficial to users who have a slow connection, device, or have JavaScript disabled and is similar to the way forms work when a URL is passed to the `action` prop. +Melewatkan Server Action ke `` memungkinkan pengguna untuk mengirimkan formulir tanpa JavaScript yang diaktifkan atau sebelum kode dimuat. Ini menguntungkan bagi pengguna yang memiliki koneksi lambat, perangkat, atau yang memiliki JavaScript dinonaktifkan dan mirip dengan cara kerja formulir ketika URL diberikan ke prop `action`. -You can use hidden form fields to provide data to the ``'s action. The Server Action will be called with the hidden form field data as an instance of [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData). +Anda dapat menggunakan *field* formulir tersembunyi untuk memberikan data ke aksi ``'s. Server Action akan dipanggil dengan data *field* formulir tersembunyi sebagai *instance* dari [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData). ```jsx import { updateCart } from './lib.js'; @@ -111,14 +111,13 @@ function AddToCart({productId}) { return ( - +
- ); } ``` -In lieu of using hidden form fields to provide data to the `
`'s action, you can call the `bind` method to supply it with extra arguments. This will bind a new argument (`productId`) to the function in addition to the `formData` that is passed as an argument to the function. +Sebagai pengganti menggunakan *field* formulir tersembunyi untuk memberikan data ke aksi ``, Anda dapat memanggil metode `bind` untuk menyuplai argumen tambahan. Ini akan mengikat argumen baru (`productId`) ke fungsi selain dari `formData` yang diteruskan sebagai argumen ke fungsi. ```jsx [[1, 8, "bind"], [2,8, "productId"], [2,4, "productId"], [3,4, "formData"]] import { updateCart } from './lib.js'; @@ -131,18 +130,18 @@ function AddToCart({productId}) { const addProductToCart = addToCart.bind(null, productId); return ( - +
); } ``` -When `
` is rendered by a [Server Component](/reference/rsc/use-client), and a [Server Action](/reference/rsc/use-server) is passed to the ``'s `action` prop, the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). +Ketika `` dirender oleh [Server Component](/reference/rsc/use-client), dan [Server Action](/reference/rsc/use-server) diteruskan ke prop `action` ``, formulir akan [ditingkatkan secara progresif](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). -### Display a pending state during form submission {/*display-a-pending-state-during-form-submission*/} -To display a pending state when a form is being submitted, you can call the `useFormStatus` Hook in a component rendered in a `` and read the `pending` property returned. +### Menampilkan status tertunda selama pengiriman formulir {/*display-a-pending-state-during-form-submission*/} +Untuk menampilkan status tertunda ketika formulir sedang dikirim, Anda dapat memanggil Hook `useFormStatus` dalam komponen yang dirender dalam `` dan membaca properti `pending` yang dikembalikan. -Here, we use the `pending` property to indicate the form is submitting. +Di sini, kami menggunakan properti `pending` untuk menunjukkan formulir sedang dikirim. @@ -154,7 +153,7 @@ function Submit() { const { pending } = useFormStatus(); return ( ); } @@ -191,12 +190,12 @@ export async function submitForm(query) { ``` -To learn more about the `useFormStatus` Hook see the [reference documentation](/reference/react-dom/hooks/useFormStatus). +Untuk mempelajari lebih lanjut tentang Hook `useFormStatus` lihat [dokumentasi referensi](/reference/react-dom/hooks/useFormStatus). -### Optimistically updating form data {/*optimistically-updating-form-data*/} -The `useOptimistic` Hook provides a way to optimistically update the user interface before a background operation, like a network request, completes. In the context of forms, this technique helps to make apps feel more responsive. When a user submits a form, instead of waiting for the server's response to reflect the changes, the interface is immediately updated with the expected outcome. +### Memperbarui data formulir secara optimis {/*optimistically-updating-form-data*/} +Hook `useOptimistic` menyediakan cara untuk memperbarui antarmuka pengguna secara optimis sebelum operasi latar belakang, seperti permintaan jaringan, selesai. Dalam konteks formulir, teknik ini membantu membuat aplikasi terasa lebih responsif. Ketika seorang pengguna mengirimkan formulir, alih-alih menunggu respons server untuk mencerminkan perubahan, antarmuka segera diperbarui dengan hasil yang diharapkan. -For example, when a user types a message into the form and hits the "Send" button, the `useOptimistic` Hook allows the message to immediately appear in the list with a "Sending..." label, even before the message is actually sent to a server. This "optimistic" approach gives the impression of speed and responsiveness. The form then attempts to truly send the message in the background. Once the server confirms the message has been received, the "Sending..." label is removed. +Sebagai contoh, ketika seorang pengguna mengetik pesan ke dalam formulir dan menekan tombol "Kirim", Hook `useOptimistic` memungkinkan pesan tersebut segera muncul dalam daftar dengan label "Mengirim...", bahkan sebelum pesan tersebut benar-benar dikirim ke server. Pendekatan "optimis" ini memberikan kesan kecepatan dan responsivitas. Formulir kemudian berusaha untuk benar-benar mengirim pesan di latar belakang. Setelah server mengonfirmasi pesan telah diterima, label "Mengirim..." dihapus. @@ -228,12 +227,12 @@ function Thread({ messages, sendMessage }) { {optimisticMessages.map((message, index) => (
{message.text} - {!!message.sending && (Sending...)} + {!!message.sending && (Mengirim...)}
))} - - + + ); @@ -241,7 +240,7 @@ function Thread({ messages, sendMessage }) { export default function App() { const [messages, setMessages] = useState([ - { text: "Hello there!", sending: false, key: 1 } + { text: "Halo!", sending: false, key: 1 } ]); async function sendMessage(formData) { const sentMessage = await deliverMessage(formData.get("message")); @@ -276,9 +275,9 @@ export async function deliverMessage(message) { [//]: # 'Uncomment the next line, and delete this line after the `useOptimistic` reference documentatino page is published' [//]: # 'To learn more about the `useOptimistic` Hook see the [reference documentation](/reference/react/hooks/useOptimistic).' -### Handling form submission errors {/*handling-form-submission-errors*/} +### Menangani kesalahan pengiriman formulir {/*handling-form-submission-errors*/} -In some cases the function called by a `
`'s `action` prop throws an error. You can handle these errors by wrapping `` in an Error Boundary. If the function called by a ``'s `action` prop throws an error, the fallback for the error boundary will be displayed. +Dalam beberapa kasus fungsi yang dipanggil oleh prop `action` dari `` melemparkan sebuah kesalahan. Anda dapat menangani kesalahan ini dengan membungkus `` dalam Error Boundary. Jika fungsi yang dipanggil oleh prop `action` dari `` melemparkan sebuah kesalahan, *fallback* untuk *error boundary* akan ditampilkan. @@ -287,20 +286,19 @@ import { ErrorBoundary } from "react-error-boundary"; export default function Search() { function search() { - throw new Error("search error"); + throw new Error("kesalahan pencarian"); } return ( There was an error while submitting the form

} + fallback={

Terjadi kesalahan saat mengirimkan formulir

} > - +
); } - ``` ```json package.json hidden @@ -318,15 +316,15 @@ export default function Search() {
-### Display a form submission error without JavaScript {/*display-a-form-submission-error-without-javascript*/} +### Menampilkan kesalahan pengiriman formulir tanpa JavaScript {/*display-a-form-submission-error-without-javascript*/} -Displaying a form submission error message before the JavaScript bundle loads for progressive enhancement requires that: +Menampilkan pesan kesalahan pengiriman formulir sebelum bundel JavaScript dimuat untuk peningkatan progresif mengharuskan bahwa: -1. `
` be rendered by a [Server Component](/reference/rsc/use-client) -1. the function passed to the ``'s `action` prop be a [Server Action](/reference/rsc/use-server) -1. the `useActionState` Hook be used to display the error message +1. `` dirender oleh [Server Component](/reference/rsc/use-client) +1. fungsi yang diteruskan ke prop `action` `` adalah [Server Action](/reference/rsc/use-server) +1. Hook `useActionState` digunakan untuk menampilkan pesan kesalahan -`useActionState` takes two parameters: a [Server Action](/reference/rsc/use-server) and an initial state. `useActionState` returns two values, a state variable and an action. The action returned by `useActionState` should be passed to the `action` prop of the form. The state variable returned by `useActionState` can be used to displayed an error message. The value returned by the [Server Action](/reference/rsc/use-server) passed to `useActionState` will be used to update the state variable. +`useActionState` mengambil dua parameter: sebuah [Server Action](/reference/rsc/use-server) dan sebuah *state* awal. `useActionState` mengembalikan dua nilai, sebuah variabel *state* dan sebuah aksi. Aksi yang dikembalikan oleh `useActionState` harus diteruskan ke prop `action` dari formulir. Variabel *state* yang dikembalikan oleh `useActionState` dapat digunakan untuk menampilkan pesan kesalahan. Nilai yang dikembalikan oleh [Server Action](/reference/rsc/use-server) yang diteruskan ke `useActionState` akan digunakan untuk memperbarui variabel *state*. @@ -340,7 +338,7 @@ export default function Page() { const email = formData.get("email"); try { await signUpNewUser(email); - alert(`Added "${email}"`); + alert(`Menambahkan "${email}"`); } catch (err) { return err.toString(); } @@ -348,12 +346,12 @@ export default function Page() { const [message, signupAction] = useActionState(signup, null); return ( <> -

Signup for my newsletter

-

Signup with the same email twice to see an error

+

Daftar untuk newsletter saya

+

Daftar dengan email yang sama dua kali untuk melihat kesalahan

- + {!!message &&

{message}

} @@ -366,7 +364,7 @@ let emails = []; export async function signUpNewUser(newEmail) { if (emails.includes(newEmail)) { - throw new Error("This email address has already been added"); + throw new Error("Alamat email ini sudah ditambahkan"); } emails.push(newEmail); } @@ -386,13 +384,13 @@ export async function signUpNewUser(newEmail) {
-Learn more about updating state from a form action with the [`useActionState`](/reference/react/useActionState) docs +Pelajari lebih lanjut tentang memperbarui *state* dari aksi formulir dengan dokumen [`useActionState`](/reference/react/useActionState). -### Handling multiple submission types {/*handling-multiple-submission-types*/} +### Menangani beberapa jenis pengiriman {/*handling-multiple-submission-types*/} -Forms can be designed to handle multiple submission actions based on the button pressed by the user. Each button inside a form can be associated with a distinct action or behavior by setting the `formAction` prop. +Formulir dapat dirancang untuk menangani beberapa aksi pengiriman berdasarkan tombol yang ditekan oleh pengguna. Setiap tombol di dalam formulir dapat dikaitkan dengan aksi atau perilaku yang berbeda dengan mengatur prop `formAction`. -When a user taps a specific button, the form is submitted, and a corresponding action, defined by that button's attributes and action, is executed. For instance, a form might submit an article for review by default but have a separate button with `formAction` set to save the article as a draft. +Ketika seorang pengguna mengetuk tombol tertentu, formulir disubmit, dan aksi yang sesuai, yang ditentukan oleh atribut dan aksi tombol tersebut, dieksekusi. Misalnya, sebuah formulir mungkin mengirimkan artikel untuk ditinjau secara default tetapi memiliki tombol terpisah dengan `formAction` diatur untuk menyimpan artikel sebagai draf. @@ -401,20 +399,20 @@ export default function Search() { function publish(formData) { const content = formData.get("content"); const button = formData.get("button"); - alert(`'${content}' was published with the '${button}' button`); + alert(`'${content}' telah dipublikasikan dengan tombol '${button}'`); } function save(formData) { const content = formData.get("content"); - alert(`Your draft of '${content}' has been saved!`); + alert(`Draf '${content}' Anda telah disimpan!`); } return (