Skip to content

Commit 6498adf

Browse files
jrr997zhangjianxiongawxiaoxian2020Yucohny
authored
docs(cn): translate reference/react/useDebugValue into Chinese (#1141)
Co-authored-by: zhangjianxiong <[email protected]> Co-authored-by: Xavi Lee <[email protected]> Co-authored-by: Yucohny <[email protected]>
1 parent db52114 commit 6498adf

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/content/reference/react/useDebugValue.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useDebugValue
44

55
<Intro>
66

7-
`useDebugValue` is a React Hook that lets you add a label to a custom Hook in [React DevTools.](/learn/react-developer-tools)
7+
`useDebugValue` 是一个 React Hook,可以让你在 [React 开发工具](/learn/react-developer-tools) 中为自定义 Hook 添加标签。
88

99
```js
1010
useDebugValue(value, format?)
@@ -16,11 +16,11 @@ useDebugValue(value, format?)
1616
1717
---
1818
19-
## Reference {/*reference*/}
19+
## 参考 {/*reference*/}
2020
2121
### `useDebugValue(value, format?)` {/*usedebugvalue*/}
2222
23-
Call `useDebugValue` at the top level of your [custom Hook](/learn/reusing-logic-with-custom-hooks) to display a readable debug value:
23+
在你的 [自定义 Hook](/learn/reusing-logic-with-custom-hooks) 的顶层调用 `useDebugValue`,以显示可读的调试值:
2424
2525
```js
2626
import { useDebugValue } from 'react';
@@ -32,22 +32,22 @@ function useOnlineStatus() {
3232
}
3333
```
3434
35-
[See more examples below.](#usage)
35+
[请看下方更多示例](#usage)
3636
37-
#### Parameters {/*parameters*/}
37+
#### 参数 {/*parameters*/}
3838
39-
* `value`: The value you want to display in React DevTools. It can have any type.
40-
* **optional** `format`: A formatting function. When the component is inspected, React DevTools will call the formatting function with the `value` as the argument, and then display the returned formatted value (which may have any type). If you don't specify the formatting function, the original `value` itself will be displayed.
39+
* `value`:你想在 React 开发工具中显示的值。可以是任何类型。
40+
* **可选** `format`:它接受一个格式化函数。当组件被检查时,React 开发工具将用 `value` 作为参数来调用格式化函数,然后显示返回的格式化值(可以是任何类型)。如果不指定格式化函数,则会显示 `value`
4141
42-
#### Returns {/*returns*/}
42+
#### 返回值 {/*returns*/}
4343
44-
`useDebugValue` does not return anything.
44+
`useDebugValue` 没有返回值。
4545
46-
## Usage {/*usage*/}
46+
## 用法 {/*usage*/}
4747
48-
### Adding a label to a custom Hook {/*adding-a-label-to-a-custom-hook*/}
48+
### 为自定义 Hook 添加标签 {/*adding-a-label-to-a-custom-hook*/}
4949
50-
Call `useDebugValue` at the top level of your [custom Hook](/learn/reusing-logic-with-custom-hooks) to display a readable <CodeStep step={1}>debug value</CodeStep> for [React DevTools.](/learn/react-developer-tools)
50+
在 [自定义 Hook](/learn/reusing-logic-with-custom-hooks) 中调用 `useDebugValue`,可以让 [React 开发工具](/learn/react-developer-tools) 显示可读的 <CodeStep step={1}>调试值</CodeStep>
5151
5252
```js [[1, 5, "isOnline ? 'Online' : 'Offline'"]]
5353
import { useDebugValue } from 'react';
@@ -59,11 +59,11 @@ function useOnlineStatus() {
5959
}
6060
```
6161
62-
This gives components calling `useOnlineStatus` a label like `OnlineStatus: "Online"` when you inspect them:
62+
这样一来,当你检查调用 `useOnlineStatus` 的组件时,它们会显示一个标签,例如 `OnlineStatus: "Online"`
6363
64-
![A screenshot of React DevTools showing the debug value](/images/docs/react-devtools-usedebugvalue.png)
64+
![React 开发工具中显示调试值的截图](/images/docs/react-devtools-usedebugvalue.png)
6565
66-
Without the `useDebugValue` call, only the underlying data (in this example, `true`) would be displayed.
66+
如果没有使用 `useDebugValue`,则只会显示底层数据(在此示例中为 `true`)。
6767
6868
<Sandpack>
6969
@@ -103,20 +103,20 @@ function subscribe(callback) {
103103
104104
<Note>
105105
106-
Don't add debug values to every custom Hook. It's most valuable for custom Hooks that are part of shared libraries and that have a complex internal data structure that's difficult to inspect.
106+
不必为每个自定义 Hook 添加调试值。这对于那些作为共享库一部分、具有复杂的内部数据结构并且难以检查的自定义 Hook 更有价值。
107107
108108
</Note>
109109
110110
---
111111
112-
### Deferring formatting of a debug value {/*deferring-formatting-of-a-debug-value*/}
112+
### 延迟格式化调试值 {/*deferring-formatting-of-a-debug-value*/}
113113
114-
You can also pass a formatting function as the second argument to `useDebugValue`:
114+
你也可以将一个格式化函数作为 `useDebugValue` 的第二个参数传入:
115115
116116
```js [[1, 1, "date", 18], [2, 1, "date.toDateString()"]]
117117
useDebugValue(date, date => date.toDateString());
118118
```
119119
120-
Your formatting function will receive the <CodeStep step={1}>debug value</CodeStep> as a parameter and should return a <CodeStep step={2}>formatted display value</CodeStep>. When your component is inspected, React DevTools will call this function and display its result.
120+
格式化函数将接收 <CodeStep step={1}>调试值</CodeStep> 作为参数,返回 <CodeStep step={2}>格式化后的显示值</CodeStep>。当你的组件被检查时,React 开发工具将调用此函数并显示其返回值。
121121
122-
This lets you avoid running potentially expensive formatting logic unless the component is actually inspected. For example, if `date` is a Date value, this avoids calling `toDateString()` on it for every render.
122+
使用格式化函数,可以避免在组件没有被检查时运行可能开销较大的格式化逻辑。例如,如果 `date` 是一个日期值,则可以避免在每次渲染时都调用 `toDateString()` 方法。

0 commit comments

Comments
 (0)