Skip to content

Commit ae3b26b

Browse files
authored
docs(cn): Translate 'use no memo' directive to Chinese (#1830)
2 parents 02531b4 + ee5c238 commit ae3b26b

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: "use no memo"
3-
titleForTitleTag: "'use no memo' directive"
3+
titleForTitleTag: "'use no memo' 指令"
44
---
55

66
<Intro>
77

8-
`"use no memo"` prevents a function from being optimized by React Compiler.
8+
`"use no memo"` 可以防止函数被 React 编译器优化。
99

1010
</Intro>
1111

1212
<InlineToc />
1313

1414
---
1515

16-
## Reference {/*reference*/}
16+
## 参考 {/*reference*/}
1717

1818
### `"use no memo"` {/*use-no-memo*/}
1919

20-
Add `"use no memo"` at the beginning of a function to prevent React Compiler optimization.
20+
在函数的开头添加 `"use no memo"` 可以阻止 React 编译器进行优化。
2121

2222
```js {1}
2323
function MyComponent() {
@@ -26,122 +26,122 @@ function MyComponent() {
2626
}
2727
```
2828

29-
When a function contains `"use no memo"`, the React Compiler will skip it entirely during optimization. This is useful as a temporary escape hatch when debugging or when dealing with code that doesn't work correctly with the compiler.
29+
当一个函数包含 "use no memo" 时,React 编译器会在优化过程中完全跳过它。在调试或处理与编译器不兼容的代码时,这是一个很有用的脱围机制。
3030

31-
#### Caveats {/*caveats*/}
31+
#### 注意事项 {/*caveats*/}
3232

33-
* `"use no memo"` must be at the very beginning of a function body, before any imports or other code (comments are OK).
34-
* The directive must be written with double or single quotes, not backticks.
35-
* The directive must exactly match `"use no memo"` or its alias `"use no forget"`.
36-
* This directive takes precedence over all compilation modes and other directives.
37-
* It's intended as a temporary debugging tool, not a permanent solution.
33+
* `"use no memo"` 必须位于函数体的最开始,在任何导入或其他代码之前(注释可以)。
34+
* 该指令必须使用双引号或单引号,而不是反引号。
35+
* 该指令必须与 `"use no memo"` 或其别名 `"use no forget"` 完全匹配。
36+
* 该指令的优先级高于所有编译模式和其他指令。
37+
* 它旨在作为一种临时的调试工具,而非永久的解决方案。
3838

39-
### How `"use no memo"` opts-out of optimization {/*how-use-no-memo-opts-out*/}
39+
### `"use no memo"` 如何选择退出优化 {/*how-use-no-memo-opts-out*/}
4040

41-
React Compiler analyzes your code at build time to apply optimizations. `"use no memo"` creates an explicit boundary that tells the compiler to skip a function entirely.
41+
React 编译器会在构建时分析你的代码以应用优化。`"use no memo"` 创建了一个明确的边界,告诉编译器完全跳过一个函数。
4242

43-
This directive takes precedence over all other settings:
44-
* In `all` mode: The function is skipped despite the global setting
45-
* In `infer` mode: The function is skipped even if heuristics would optimize it
43+
该指令的优先级高于所有其他设置:
44+
* `all` 模式下:尽管有全局设置,该函数仍会被跳过
45+
* `infer` 模式下:即使启发式算法会优化该函数,它也仍会被跳过
4646

47-
The compiler treats these functions as if the React Compiler wasn't enabled, leaving them exactly as written.
47+
编译器会像未启用 React 编译器一样对待这些函数,让它们保持原样。
4848

49-
### When to use `"use no memo"` {/*when-to-use*/}
49+
### 何时使用 `"use no memo"` {/*when-to-use*/}
5050

51-
`"use no memo"` should be used sparingly and temporarily. Common scenarios include:
51+
`"use no memo"` 应谨慎并临时使用。常见场景包括:
5252

53-
#### Debugging compiler issues {/*debugging-compiler*/}
54-
When you suspect the compiler is causing issues, temporarily disable optimization to isolate the problem:
53+
#### 调试编译器问题 {/*debugging-compiler*/}
54+
当你怀疑编译器引起问题时,可以暂时禁用优化来隔离问题:
5555

5656
```js
5757
function ProblematicComponent({ data }) {
58-
"use no memo"; // TODO: Remove after fixing issue #123
58+
"use no memo"; // TODO: 修复 issue #123 后移除
5959

60-
// Rules of React violations that weren't statically detected
60+
// 未被静态检测到的违反 React 规则的代码
6161
// ...
6262
}
6363
```
6464

65-
#### Third-party library integration {/*third-party*/}
66-
When integrating with libraries that might not be compatible with the compiler:
65+
#### 第三方库集成 {/*third-party*/}
66+
当与可能不兼容编译器的库集成时:
6767

6868
```js
6969
function ThirdPartyWrapper() {
7070
"use no memo";
7171

72-
useThirdPartyHook(); // Has side effects that compiler might optimize incorrectly
72+
useThirdPartyHook(); // 存在可能被编译器错误优化的副作用
7373
// ...
7474
}
7575
```
7676

7777
---
7878

79-
## Usage {/*usage*/}
80-
81-
The `"use no memo"` directive is placed at the beginning of a function body to prevent React Compiler from optimizing that function:
79+
## 用法 {/*usage*/}
8280

81+
`"use no memo"` 指令放在函数体的开头,以防止 React 编译器优化该函数:
82+
8383
```js
8484
function MyComponent() {
8585
"use no memo";
86-
// Function body
86+
// 函数体
8787
}
8888
```
8989

90-
The directive can also be placed at the top of a file to affect all functions in that module:
90+
该指令也可以放在文件的顶部,以影响该模块中的所有函数:
9191

9292
```js
9393
"use no memo";
9494

95-
// All functions in this file will be skipped by the compiler
95+
// 此文件中的所有函数都将被编译器跳过
9696
```
9797

98-
`"use no memo"` at the function level overrides the module level directive.
98+
`"use no memo"` 在函数级别覆盖模块级别指令。
9999

100100
---
101101

102-
## Troubleshooting {/*troubleshooting*/}
102+
## 故障排查 {/*troubleshooting*/}
103103

104-
### Directive not preventing compilation {/*not-preventing*/}
104+
### 指令未阻止编译 {/*not-preventing*/}
105105

106-
If `"use no memo"` isn't working:
106+
如果 `"use no memo"` 不起作用:
107107

108108
```js
109-
//Wrong - directive after code
109+
//错误 - 指令在代码之后
110110
function Component() {
111111
const data = getData();
112-
"use no memo"; // Too late!
112+
"use no memo"; // 太晚了!
113113
}
114114

115-
//Correct - directive first
115+
//正确 - 指令在最前面
116116
function Component() {
117117
"use no memo";
118118
const data = getData();
119119
}
120120
```
121121

122-
Also check:
123-
* Spelling - must be exactly `"use no memo"`
124-
* Quotes - must use single or double quotes, not backticks
122+
同时检查:
123+
* 拼写 - 必须是 `"use no memo"`
124+
* 引号 - 必须使用单引号或双引号,而不是反引号
125125

126-
### Best practices {/*best-practices*/}
126+
### 最佳实践 {/*best-practices*/}
127127

128-
**Always document why** you're disabling optimization:
128+
**始终记录** 你禁用优化的 **原因**
129129

130130
```js
131-
//Good - clear explanation and tracking
131+
//好的 - 有清晰的解释和追踪
132132
function DataProcessor() {
133-
"use no memo"; // TODO: Remove after fixing rule of react violation
133+
"use no memo"; // TODO:修复违反 React 规则的问题后移除
134134
// ...
135135
}
136136

137-
//Bad - no explanation
137+
//坏的 - 没有解释
138138
function Mystery() {
139139
"use no memo";
140140
// ...
141141
}
142142
```
143143

144-
### See also {/*see-also*/}
144+
### 参见 {/*see-also*/}
145145

146-
* [`"use memo"`](/reference/react-compiler/directives/use-memo) - Opt into compilation
147-
* [React Compiler](/learn/react-compiler) - Getting started guide
146+
* [`"use memo"`](/reference/react-compiler/directives/use-memo) - 选择加入编译
147+
* [React 编译器](/learn/react-compiler) - 入门指南

0 commit comments

Comments
 (0)