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/react-dom/components/form.md
+38-38
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,14 @@ canary: true
5
5
6
6
<Canary>
7
7
8
-
React's extensions to `<form>`are currently only available in React's canary and experimental channels. In stable releases of React `<form>`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).
The [built-in browser `<form>`component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)lets you create interactive controls for submitting information.
@@ -27,11 +27,11 @@ The [built-in browser `<form>` component](https://developer.mozilla.org/en-US/do
27
27
28
28
---
29
29
30
-
## Reference {/*reference*/}
30
+
## リファレンス {/*reference*/}
31
31
32
32
### `<form>` {/*form*/}
33
33
34
-
To create interactive controls for submitting information, render the [built-in browser `<form>`component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
[`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 `<button>`, `<input type="submit">`, or `<input type="image">`component.
49
+
[`action`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action):URL または関数。`action`として URL が渡された場合、フォームは HTML の form コンポーネントと同様に動作します。`action`として関数が渡された場合、その関数がフォームの送信を処理します。`action`に渡された関数は非同期でもよく、送信されたフォームの [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)を唯一の引数として呼び出されます。`action`は、`<button>`、`<input type="submit">`、または `<input type="image">`コンポーネントの `formAction` プロパティによって上書きされることがあります。
50
50
51
-
#### Caveats {/*caveats*/}
51
+
#### 注意点 {/*caveats*/}
52
52
53
-
*When a function is passed to `action`or`formAction`the HTTP method will be POST regardless of value of the `method`prop.
53
+
*`action`または`formAction`に関数が渡された場合、HTTP メソッドは `method`の値に関わらず POST になります。
54
54
55
55
---
56
56
57
-
## Usage {/*usage*/}
57
+
## 使用法 {/*usage*/}
58
58
59
-
### Handle form submission on the client {/*handle-form-submission-on-the-client*/}
Pass a function to the `action`prop of form to run the function when the form is submitted. [`formData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)will be passed to the function as an argument so you can access the data submitted by the form. This differs from the conventional [HTML action](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action), which only accepts URLs.
Render a `<form>`with an input and submit button. Pass a Server Action (a function marked with [`'use server'`](/reference/react/use-server)) to the `action`prop of form to run the function when the form is submitted.
96
+
`<form>`をレンダーし、入力フィールドと送信ボタンを配置します。フォームが送信されたときに関数を実行するために、サーバアクション(Server Action; [`'use server'`](/reference/react/use-server) でマークされた関数)を form の `action`に渡します。
97
97
98
-
Passing a Server Action to `<form action>`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.
You can use hidden form fields to provide data to the `<form>`'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).
@@ -118,7 +118,7 @@ function AddToCart({productId}) {
118
118
}
119
119
```
120
120
121
-
In lieu of using hidden form fields to provide data to the `<form>`'s action, you can call the <CodeStepstep={1}>`bind`</CodeStep> method to supply it with extra arguments. This will bind a new argument (<CodeStepstep={2}>`productId`</CodeStep>) to the function in addition to the <CodeStepstep={3}>`formData`</CodeStep> that is passed as a argument to the function.
@@ -137,12 +137,12 @@ function AddToCart({productId}) {
137
137
}
138
138
```
139
139
140
-
When `<form>` is rendered by a [Server Component](/reference/react/use-client), and a [Server Action](/reference/react/use-server) is passed to the `<form>`'s `action` prop, the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).
### Display a pending state during form submission {/*display-a-pending-state-during-form-submission*/}
143
-
To display a pending state when a form is being submitted, you can call the `useFormStatus` Hook in a component rendered in a `<form>`and read the`pending`property returned.
### Optimistically updating form data {/*optimistically-updating-form-data*/}
197
-
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.
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.
In some cases the function called by a `<form>`'s `action`prop throw an error. You can handle these errors by wrapping `<form>`in an Error Boundary. If the function called by a `<form>`'s `action`prop throws an error, the fallback for the error boundary will be displayed.
`useFormState`takes two parameters: a [Server Action](/reference/react/use-server) and an initial state. `useFormState` returns two values, a state variable and an action. The action returned by `useFormState`should be passed to the `action`prop of the form. The state variable returned by `useFormState`can be used to displayed an error message. The value returned by the [Server Action](/reference/react/use-server) passed to `useFormState` will be used to update the state variable.
329
+
`useFormState`は[サーバアクション](/reference/react/use-server)と初期 state の 2 つの引数を受け取り、state 変数とアクションの 2 つの値を返します。`useFormState`が返したアクションは、フォームの `action`プロパティに渡します。`useFormState` が返した state 変数は、エラーメッセージを表示するために使用できます。`useFormState`に渡す[サーバアクション](/reference/react/use-server)が返す値は、state 変数を更新するために使用されます。
330
330
331
331
<Sandpack>
332
332
@@ -386,13 +386,13 @@ export async function signUpNewUser(newEmail) {
386
386
387
387
</Sandpack>
388
388
389
-
Learn more about updating state from a form action with the [`useFormState`](/reference/react-dom/hooks/useFormState)docs
389
+
フォームアクションから state を更新する方法については、[`useFormState`](/reference/react-dom/hooks/useFormState)のドキュメントを参照してください。
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.
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.
0 commit comments