Skip to content

Commit 4e55207

Browse files
Update react-calls-components-and-hooks.md (#1693)
Co-authored-by: Xavi Lee <[email protected]> Co-authored-by: Xavi Lee <[email protected]>
1 parent 21def1b commit 4e55207

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/content/reference/rules/react-calls-components-and-hooks.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ React 必须决定 [在渲染过程中](/reference/rules/components-and-hooks-mu
1717

1818
```js {2}
1919
function BlogPost() {
20-
return <Layout><Article /></Layout>; //Good: Only use components in JSX
20+
return <Layout><Article /></Layout>; //正确的:只在 JSX 中使用组件
2121
}
2222
```
2323

2424
```js {2}
2525
function BlogPost() {
26-
return <Layout>{Article()}</Layout>; // 🔴 Bad: Never call them directly
26+
return <Layout>{Article()}</Layout>; // 🔴 错误的:不要直接调用组件函数
2727
}
2828
```
2929

@@ -53,7 +53,7 @@ Hook 应当尽可能保持“静态”。这意味着你不应该动态地改变
5353

5454
```js {2}
5555
function ChatInput() {
56-
const useDataWithLogging = withLogging(useData); // 🔴 Bad: don't write higher order Hooks
56+
const useDataWithLogging = withLogging(useData); // 🔴 错误的:不要编写高阶 Hook
5757
const data = useDataWithLogging();
5858
}
5959
```
@@ -62,11 +62,11 @@ Hook 应该是不可变的,不应被动态改变。与其动态地改变 Hook
6262

6363
```js {2,6}
6464
function ChatInput() {
65-
const data = useDataWithLogging(); //Good: Create a new version of the Hook
65+
const data = useDataWithLogging(); //正确的:创建一个新的 Hook
6666
}
6767

6868
function useDataWithLogging() {
69-
// ... Create a new version of the Hook and inline the logic here
69+
// ... 创建一个新的 Hook,并将逻辑直接内联到这里
7070
}
7171
```
7272

@@ -76,7 +76,7 @@ Hook 也不应该被动态使用,例如,不应该通过将 Hook 作为值传
7676

7777
```js {2}
7878
function ChatInput() {
79-
return <Button useData={useDataWithLogging} /> // 🔴 Bad: don't pass Hooks as props
79+
return <Button useData={useDataWithLogging} /> // 🔴 错误的:不要通过 props 传递 Hook
8080
}
8181
```
8282

@@ -88,12 +88,12 @@ function ChatInput() {
8888
}
8989

9090
function Button() {
91-
const data = useDataWithLogging(); //Good: Use the Hook directly
91+
const data = useDataWithLogging(); //正确的:直接使用 Hook
9292
}
9393

9494
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+
9797
}
9898
```
9999

0 commit comments

Comments
 (0)