@@ -17,13 +17,13 @@ React 必须决定 [在渲染过程中](/reference/rules/components-and-hooks-mu
17
17
18
18
``` js {2}
19
19
function BlogPost () {
20
- return < Layout>< Article / >< / Layout> ; // ✅ Good: Only use components in JSX
20
+ return < Layout>< Article / >< / Layout> ; // ✅ 正确的:只在 JSX 中使用组件
21
21
}
22
22
```
23
23
24
24
``` js {2}
25
25
function BlogPost () {
26
- return < Layout> {Article ()}< / Layout> ; // 🔴 Bad: Never call them directly
26
+ return < Layout> {Article ()}< / Layout> ; // 🔴 错误的:不要直接调用组件函数
27
27
}
28
28
```
29
29
@@ -53,7 +53,7 @@ Hook 应当尽可能保持“静态”。这意味着你不应该动态地改变
53
53
54
54
``` js {2}
55
55
function ChatInput () {
56
- const useDataWithLogging = withLogging (useData); // 🔴 Bad: don't write higher order Hooks
56
+ const useDataWithLogging = withLogging (useData); // 🔴 错误的:不要编写高阶 Hook
57
57
const data = useDataWithLogging ();
58
58
}
59
59
```
@@ -62,11 +62,11 @@ Hook 应该是不可变的,不应被动态改变。与其动态地改变 Hook
62
62
63
63
``` js {2,6}
64
64
function ChatInput () {
65
- const data = useDataWithLogging (); // ✅ Good: Create a new version of the Hook
65
+ const data = useDataWithLogging (); // ✅ 正确的:创建一个新的 Hook
66
66
}
67
67
68
68
function useDataWithLogging () {
69
- // ... Create a new version of the Hook and inline the logic here
69
+ // ... 创建一个新的 Hook,并将逻辑直接内联到这里
70
70
}
71
71
```
72
72
@@ -76,7 +76,7 @@ Hook 也不应该被动态使用,例如,不应该通过将 Hook 作为值传
76
76
77
77
``` js {2}
78
78
function ChatInput () {
79
- return < Button useData= {useDataWithLogging} / > // 🔴 Bad: don't pass Hooks as props
79
+ return < Button useData= {useDataWithLogging} / > // 🔴 错误的:不要通过 props 传递 Hook
80
80
}
81
81
```
82
82
@@ -88,12 +88,12 @@ function ChatInput() {
88
88
}
89
89
90
90
function Button () {
91
- const data = useDataWithLogging (); // ✅ Good: Use the Hook directly
91
+ const data = useDataWithLogging (); // ✅ 正确的:直接使用 Hook
92
92
}
93
93
94
94
function useDataWithLogging () {
95
- // If there's any conditional logic to change the Hook's behavior, it should be inlined into
96
- // the Hook
95
+ // 如果有任何条件逻辑需要改变 Hook 的行为,应将其直接内联到 Hook 中
96
+
97
97
}
98
98
```
99
99
0 commit comments