Skip to content

Commit 6685880

Browse files
Yucohnyawxiaoxian2020loveloki
authored
docs(cn): translate reference/react-dom/useFormStatus into Chinese (#1348)
Co-authored-by: Xavi Lee <[email protected]> Co-authored-by: Xleine <[email protected]>
1 parent f3f6a85 commit 6685880

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

src/content/reference/react-dom/hooks/useFormStatus.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ canary: true
55

66
<Canary>
77

8-
The `useFormStatus` Hook is currently only available in React's canary and experimental channels. Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
8+
`useFormStatus` Hook 目前仅在 React canary experimental 渠道中可用。在此处了解更多关于 [React 发布渠道](/community/versioning-policy#all-release-channels) 的信息。
99

1010
</Canary>
1111

1212
<Intro>
1313

14-
`useFormStatus` is a Hook that gives you status information of the last form submission.
14+
`useFormStatus` 是一个提供上次表单提交状态信息的 Hook
1515

1616
```js
1717
const { pending, data, method, action } = useFormStatus();
@@ -23,19 +23,19 @@ const { pending, data, method, action } = useFormStatus();
2323

2424
---
2525

26-
## Reference {/*reference*/}
26+
## 参考 {/*reference*/}
2727

2828
### `useFormStatus()` {/*use-form-status*/}
2929

30-
The `useFormStatus` Hook provides status information of the last form submission.
30+
`useFormStatus` Hook 提供了上次表单提交的状态信息。
3131

3232
```js {5},[[1, 6, "status.pending"]]
3333
import { useFormStatus } from "react-dom";
3434
import action from './actions';
3535

3636
function Submit() {
3737
const status = useFormStatus();
38-
return <button disabled={status.pending}>Submit</button>
38+
return <button disabled={status.pending}>提交</button>
3939
}
4040

4141
export default App() {
@@ -47,42 +47,42 @@ export default App() {
4747
}
4848
```
4949

50-
To get status information, the `Submit` component must be rendered within a `<form>`. The Hook returns information like the <CodeStep step={1}>`pending`</CodeStep> property which tells you if the form is actively submitting.
50+
`Submit` 组件必须在 `<form>` 内部渲染以获取状态信息。该 Hook 返回诸如 <CodeStep step={1}>`pending`</CodeStep> 属性的信息,用于指示表单是否正在提交中。
5151

52-
In the above example, `Submit` uses this information to disable `<button>` presses while the form is submitting.
52+
在上面的示例中,`Submit` 利用此信息来在表单提交时禁用 `<button>` 按钮的按压操作。
5353

54-
[See more examples below.](#usage)
54+
[参见下方更多示例](#usage)
5555

56-
#### Parameters {/*parameters*/}
56+
#### 参数 {/*parameters*/}
5757

58-
`useFormStatus` does not take any parameters.
58+
`useFormStatus` 不接收任何参数。
5959

60-
#### Returns {/*returns*/}
60+
#### 返回值 {/*returns*/}
6161

62-
A `status` object with the following properties:
62+
`useFormStatus` 返回一个包含以下属性的 `status` 对象:
6363

64-
* `pending`: A boolean. If `true`, this means the parent `<form>` is pending submission. Otherwise, `false`.
64+
* `pending`:布尔值。如果为 `true`,则表示父级 `<form>` 正在等待提交;否则为 `false`
6565

66-
* `data`: An object implementing the [`FormData interface`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) that contains the data the parent `<form>` is submitting. If there is no active submission or no parent `<form>`, it will be `null`.
66+
* `data`:实现了 [`FormData interface`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) 的对象,包含父级 `<form>` 正在提交的数据;如果没有进行提交或没有父级 `<form>`,它将为 `null`
6767

68-
* `method`: A string value of either `'get'` or `'post'`. This represents whether the parent `<form>` is submitting with either a `GET` or `POST` [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). By default, a `<form>` will use the `GET` method and can be specified by the [`method`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#method) property.
68+
* `method`:字符串,可以是 `'get'` `'post'`。表示父级 `<form>` 使用 `GET` `POST` [HTTP 方法](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) 进行提交。默认情况下,`<form>` 将使用 `GET` 方法,并可以通过 [`method`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#method) 属性指定。
6969

70-
[//]: # (Link to `<form>` documentation. "Read more on the `action` prop on `<form>`.")
71-
* `action`: A reference to the function passed to the `action` prop on the parent `<form>`. If there is no parent `<form>`, the property is `null`. If there is a URI value provided to the `action` prop, or no `action` prop specified, `status.action` will be `null`.
70+
[//]: # (链接到 `<form>` 文档。"在 `<form>` 上的 `action` 属性上阅读更多信息。")
71+
* `action`:一个传递给父级 `<form>``action` 属性的函数引用。如果没有父级 `<form>`,则该属性为 `null`。如果在 `action` 属性上提供了 URI 值,或者未指定 `action` 属性,`status.action` 将为 `null`
7272

73-
#### Caveats {/*caveats*/}
73+
#### 注意 {/*caveats*/}
7474

75-
* The `useFormStatus` Hook must be called from a component that is rendered inside a `<form>`.
76-
* `useFormStatus` will only return status information for a parent `<form>`. It will not return status information for any `<form>` rendered in that same component or children components.
75+
* `useFormStatus` Hook 必须从在 `<form>` 内渲染的组件中调用。
76+
* `useFormStatus` 仅会返回父级 `<form>` 的状态信息。它不会返回同一组件或子组件中渲染的任何 `<form>` 的状态信息。
7777

7878
---
7979

80-
## Usage {/*usage*/}
80+
## 用法 {/*usage*/}
8181

82-
### Display a pending state during form submission {/*display-a-pending-state-during-form-submission*/}
83-
To display a pending state while a form is submitting, you can call the `useFormStatus` Hook in a component rendered in a `<form>` and read the `pending` property returned.
82+
### 在表单提交期间显示待定状态 {/*display-a-pending-state-during-form-submission*/}
83+
可以在 `<form>` 中渲染的子组件中调用 `useFormStatus` Hook,并读取返回的 `pending` 属性,以在表单提交期间显示待定状态。
8484

85-
Here, we use the `pending` property to indicate the form is submitting.
85+
下面的示例使用 `pending` 属性指示表单正在提交。
8686

8787
<Sandpack>
8888

@@ -94,7 +94,7 @@ function Submit() {
9494
const { pending } = useFormStatus();
9595
return (
9696
<button type="submit" disabled={pending}>
97-
{pending ? "Submitting..." : "Submit"}
97+
{pending ? "提交中……" : "提交"}
9898
</button>
9999
);
100100
}
@@ -133,30 +133,30 @@ export async function submitForm(query) {
133133

134134
<Pitfall>
135135

136-
##### `useFormStatus` will not return status information for a `<form>` rendered in the same component. {/*useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component*/}
136+
##### `useFormStatus` 不会返回在同一组件中渲染的 `<form>` 的状态信息 {/*useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component*/}
137137

138-
The `useFormStatus` Hook only returns status information for a parent `<form>` and not for any `<form>` rendered in the same component calling the Hook, or child components.
138+
`useFormStatus` Hook 只会返回父级 `<form>` 的状态信息,而不会返回在调用 Hook 的同一组件中渲染的任何 `<form>` 的状态信息,也不会返回子组件的状态信息。
139139

140140
```js
141141
function Form() {
142-
// 🚩 `pending` will never be true
143-
// useFormStatus does not track the form rendered in this component
142+
// 🚩 `pending` 永远不会为 true
143+
// useFormStatus 不会跟踪在此组件中渲染的表单
144144
const { pending } = useFormStatus();
145145
return <form action={submit}></form>;
146146
}
147147
```
148148

149-
Instead call `useFormStatus` from inside a component that is located inside `<form>`.
149+
正确的做法是从位于 `<form>` 内部的组件中调用 `useFormStatus`
150150

151151
```js
152152
function Submit() {
153-
// ✅ `pending` will be derived from the form that wraps the Submit component
153+
// ✅ `pending` 将从包裹 Submit 组件的表单派生
154154
const { pending } = useFormStatus();
155155
return <button disabled={pending}>...</button>;
156156
}
157157

158158
function Form() {
159-
// This is the <form> `useFormStatus` tracks
159+
// <form> `useFormStatus` 将会追踪它
160160
return (
161161
<form action={submit}>
162162
<Submit />
@@ -167,11 +167,11 @@ function Form() {
167167

168168
</Pitfall>
169169

170-
### Read the form data being submitted {/*read-form-data-being-submitted*/}
170+
### 查看正在提交的表单数据 {/*read-form-data-being-submitted*/}
171171

172-
You can use the `data` property of the status information returned from `useFormStatus` to display what data is being submitted by the user.
172+
可以使用从 `useFormStatus` 返回的状态信息中的 `data` 属性来显示用户正在提交的数据是什么。
173173

174-
Here, we have a form where users can request a username. We can use `useFormStatus` to display a temporary status message confirming what username they have requested.
174+
下面的示例中有一个表单,用户可以请求一个用户名。那么可以使用 `useFormStatus` 来显示一个临时状态消息,确认请求了什么用户名。
175175

176176
<Sandpack>
177177

@@ -203,13 +203,13 @@ export default function UsernameForm() {
203203

204204
return (
205205
<>
206-
<label>Request a Username: </label><br />
206+
<label>请求用户名:</label><br />
207207
<input type="text" name="username" />
208208
<button type="submit" disabled={pending}>
209-
{pending ? 'Submitting...' : 'Submit'}
209+
{pending ? '提交中……' : '提交'}
210210
</button>
211211
{showSubmitted ? (
212-
<p>Submitted request for username: {submittedUsername.current}</p>
212+
<p>提交请求用户名:{submittedUsername.current}</p>
213213
) : null}
214214
</>
215215
);
@@ -250,12 +250,12 @@ export async function submitForm(query) {
250250
251251
---
252252
253-
## Troubleshooting {/*troubleshooting*/}
253+
## 疑难解答 {/*troubleshooting*/}
254254
255-
### `status.pending` is never `true` {/*pending-is-never-true*/}
255+
### `status.pending` 从不为 `true` {/*pending-is-never-true*/}
256256
257-
`useFormStatus` will only return status information for a parent `<form>`.
257+
`useFormStatus` 仅会返回父级 `<form>` 的状态信息。
258258
259-
If the component that calls `useFormStatus` is not nested in a `<form>`, `status.pending` will always return `false`. Verify `useFormStatus` is called in a component that is a child of a `<form>` element.
259+
如果调用 `useFormStatus` 的组件未嵌套在 `<form>` 中,`status.pending` 总是返回 `false`。请验证 `useFormStatus` 是否在 `<form>` 元素的子组件中调用。
260260
261-
`useFormStatus` will not track the status of a `<form>` rendered in the same component. See [Pitfall](#useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component) for more details.
261+
`useFormStatus` 不会追踪同一组件中渲染的 `<form>` 的状态。参阅 [陷阱](#useformstatus-will-not-return-status-information-for-a-form-rendered-in-the-same-component) 以了解更多详细信息。

0 commit comments

Comments
 (0)