Skip to content

Commit e911d84

Browse files
committed
i18n
1 parent 9db0d05 commit e911d84

File tree

87 files changed

+284
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+284
-292
lines changed

questions/explain-one-way-data-flow-of-react-and-its-benefits/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"98a50d6b",
2525
"f9866dae",
2626
"1f4770e5",
27-
"5f3a5413"
27+
"db46a0c"
2828
]
2929
},
3030
"targets": {
@@ -47,7 +47,7 @@
4747
"98a50d6b",
4848
"f9866dae",
4949
"1f4770e5",
50-
"5f3a5413"
50+
"db46a0c"
5151
]
5252
}
5353
}

questions/explain-one-way-data-flow-of-react-and-its-benefits/zh-CN.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ export default ChildComponent;
7373

7474
## 延伸阅读
7575

76-
* [React 组件和 props 文档](https://react.dev/learn/passing-props-to-a-component)
76+
* [React 组件和 Props 文档](https://react.dev/learn/passing-props-to-a-component)
7777
* [React 状态文档](https://react.dev/learn/state-a-components-memory)
7878
* [React 提升状态文档](https://react.dev/learn/sharing-state-between-components)

questions/explain-server-side-rendering-of-react-applications-and-its-benefits/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"4fddd280",
2828
"7e9fbf0a",
2929
"1f4770e5",
30-
"b9da6017"
30+
"a7a5cfdf"
3131
]
3232
},
3333
"targets": {
@@ -53,7 +53,7 @@
5353
"4fddd280",
5454
"7e9fbf0a",
5555
"1f4770e5",
56-
"b9da6017"
56+
"a7a5cfdf"
5757
]
5858
}
5959
}

questions/explain-server-side-rendering-of-react-applications-and-its-benefits/zh-CN.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ export default Home;
6464

6565
## 延伸阅读
6666

67+
* [Next.js 文档](https://nextjs.org/docs)
68+
* [React 服务器组件](https://react.dev/reference/rsc/server-components)
6769
* [React 中的服务器端渲染](https://react.dev/reference/react-dom/server)

questions/explain-static-generation-of-react-applications-and-its-benefits/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"8cc0201c",
2929
"6e0b9e77",
3030
"1f4770e5",
31-
"dd0ff6d9"
31+
"92d795c7"
3232
]
3333
},
3434
"targets": {
@@ -55,7 +55,7 @@
5555
"8cc0201c",
5656
"6e0b9e77",
5757
"1f4770e5",
58-
"dd0ff6d9"
58+
"92d795c7"
5959
]
6060
}
6161
}

questions/explain-static-generation-of-react-applications-and-its-benefits/zh-CN.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ export default HomePage;
7878

7979
* [Next.js 关于静态生成的文档](https://nextjs.org/docs/basic-features/pages#static-generation-recommended)
8080
* [React 官方文档](https://react.dev/learn)
81-
* [静态网站生成器比较](https://www.staticgen.com/)
81+
* [静态站点生成器比较](https://www.staticgen.com/)

questions/explain-the-composition-pattern-in-react/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"fb38abd3",
2626
"4352471d",
2727
"1f4770e5",
28-
"4803c63c"
28+
"35076104"
2929
]
3030
},
3131
"targets": {
@@ -49,7 +49,7 @@
4949
"fb38abd3",
5050
"4352471d",
5151
"1f4770e5",
52-
"4803c63c"
52+
"35076104"
5353
]
5454
}
5555
}

questions/explain-the-composition-pattern-in-react/zh-CN.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ function App() {
8282

8383
## 延伸阅读
8484

85-
* [React 模式:组合](https://reactpatterns.com/#composition)
85+
* [React 中的组合](https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/)
8686
* [关于 React 组合的 Medium 文章](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)

questions/explain-the-presentational-vs-container-component-pattern-in-react/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"2819c383",
2626
"11aa9a75",
2727
"1f4770e5",
28-
"e91c66f1"
28+
"4caa2581"
2929
]
3030
},
3131
"targets": {
@@ -49,7 +49,7 @@
4949
"2819c383",
5050
"11aa9a75",
5151
"1f4770e5",
52-
"e91c66f1"
52+
"4caa2581"
5353
]
5454
}
5555
}

questions/explain-the-presentational-vs-container-component-pattern-in-react/zh-CN.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ export default connect(null, mapDispatchToProps)(ButtonContainer);
7979

8080
## 延伸阅读
8181

82-
* [React 组件和 props 文档](https://react.dev/learn/passing-props-to-a-component)
83-
* [Dan Abramov 关于展示组件和容器组件的文章](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
84-
* [Redux 关于展示组件和容器组件的文档](https://redux.js.org/basics/usage-with-react#presentational-and-container-components)
82+
* [React documentation on components and props](https://react.dev/learn/passing-props-to-a-component)
83+
* [Dan Abramov's article on presentational and container components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
84+
* [Redux documentation on presentational and container components](https://redux.js.org/basics/usage-with-react#presentational-and-container-components)

questions/explain-what-happens-when-setstate-is-called-in-react/en-US.langnostic.json

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
11
{
22
"frontmatter": {
3-
"title": "99a772ae"
3+
"title": "c395a10b"
44
},
55
"content": {
66
"source": {
77
"locale": "en-US",
88
"hashes": [
99
"77da26a5",
10-
"59b77cf6",
10+
"bc93022f",
1111
"2a7816d0",
12-
"dd3af1e8",
12+
"ea57d6f1",
1313
"8bf1f14",
14-
"47573ea3",
15-
"4424d34c",
16-
"ca3a9734",
17-
"a1a1f686",
18-
"f1b7521e",
14+
"2b5b2680",
15+
"56f02148",
16+
"7b51019",
17+
"6ddd5305",
18+
"3294def3",
1919
"4610812b",
20-
"37c0d330",
21-
"af3a5231",
22-
"b3d2321d",
23-
"8a3c0c83",
24-
"44005839",
25-
"9d5627af",
26-
"f69b7721",
20+
"bdc4dbb4",
21+
"28eb626b",
22+
"9de13ed8",
23+
"f1596715",
2724
"1f4770e5",
28-
"aacf0b32"
25+
"fa842b3f"
2926
]
3027
},
3128
"targets": {
3229
"zh-CN": [
3330
"77da26a5",
34-
"59b77cf6",
31+
"bc93022f",
3532
"2a7816d0",
36-
"dd3af1e8",
33+
"ea57d6f1",
3734
"8bf1f14",
38-
"47573ea3",
39-
"4424d34c",
40-
"ca3a9734",
41-
"a1a1f686",
42-
"f1b7521e",
35+
"2b5b2680",
36+
"56f02148",
37+
"7b51019",
38+
"6ddd5305",
39+
"3294def3",
4340
"4610812b",
44-
"37c0d330",
45-
"af3a5231",
46-
"b3d2321d",
47-
"8a3c0c83",
48-
"44005839",
49-
"9d5627af",
50-
"f69b7721",
41+
"bdc4dbb4",
42+
"28eb626b",
43+
"9de13ed8",
44+
"f1596715",
5145
"1f4770e5",
52-
"aacf0b32"
46+
"fa842b3f"
5347
]
5448
}
5549
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
---
2-
title: 解释在 React 中调用 `setState` 时会发生什么
2+
title: 解释在 React 中调用 `useState` 设置器函数时会发生什么
33
---
44

55
## 总结
66

7-
React 中调用 `setState` 时,它会安排对组件状态对象的更新。然后,React 将新状态与当前状态合并,并触发组件的重新渲染。此过程是异步的,这意味着状态更改可能不会立即发生。React 会批量处理多个 `setState` 调用以进行性能优化
7+
当在 React 中调用 `useState` 钩子返回的设置器函数时,它会安排对组件状态值的更新。然后,React 会将组件重新渲染与新状态排队。此过程通常是异步的,并且 React 会将多个状态更新批处理在一起以提高性能
88

99
***
1010

11-
## 在 React 中调用 `setState` 时会发生什么
11+
## 调用 `useState` 设置器时会发生什么
1212

1313
### 状态更新调度
1414

15-
当调用 `setState` 时,React 会安排对组件状态的更新。这意味着状态更改不会立即发生。相反,React 会将组件标记为需要更新,稍后将处理状态更改
15+
当您调用 `useState` 提供的设置器函数(例如,`setCount`时,React 会安排对该特定状态变量的更新。这不会立即发生;React 会将组件标记为需要使用更新后的状态值重新渲染
1616

1717
```javascript
18-
this.setState({ count: this.state.count + 1 });
18+
const [count, setCount] = useState(0);
19+
// ...
20+
setCount(count + 1); // 安排更新以将 'count' 设置为 1
1921
```
2022

21-
### 合并状态
23+
### 状态替换
2224

23-
React 将新状态与当前状态合并。`setState` 方法执行浅合并,这意味着它仅更新新状态对象中指定的属性,而保留其余属性不变
25+
`useState` 设置器函数**完全替换**您提供的新值中的旧状态值。如果您的状态是一个对象,并且您只想更新一个属性,则需要手动展开旧状态并覆盖特定属性
2426

2527
```javascript
26-
this.setState({ name: 'John' });
27-
// 仅更新 'name' 属性,其他状态属性保持不变
28+
const [user, setUser] = useState({ name: 'Anon', age: 99 });
29+
30+
// 仅更新 name,您必须展开旧状态:
31+
setUser((prevState) => ({ ...prevState, name: 'John' }));
32+
// 如果您只是执行 setUser({ name: 'John' }),则 'age' 属性将会丢失。
2833
```
2934

3035
### 重新渲染
3136

32-
合并状态后,React 会触发组件的重新渲染。将调用组件的 `render` 方法,并更新虚拟 DOM。然后,React 将虚拟 DOM 与实际 DOM 进行比较,并对实际 DOM 进行必要的更新。
33-
34-
### 异步性质
35-
36-
`setState` 方法是异步的。React 会批量处理多个 `setState` 调用以进行性能优化。这意味着,如果您连续多次调用 `setState`,React 可能会将它们合并为单个更新。
37-
38-
```javascript
39-
this.setState({ count: this.state.count + 1 });
40-
this.setState({ count: this.state.count + 1 });
41-
// React 可能会将这些更新批处理为单个更新
42-
```
37+
在安排状态更新后,React 最终将触发组件的重新渲染。函数组件主体将使用新的状态值再次执行。React 更新其虚拟 DOM,将其与之前的版本进行比较,并仅在必要时有效地更新实际 DOM。
4338

44-
### 回调函数
39+
### 异步性质和批处理
4540

46-
您可以将回调函数作为第二个参数传递给 `setState`。此函数将在状态更新且组件重新渲染后被调用
41+
`useState` 设置器触发的状态更新通常是异步和批处理的。如果您在同一个事件处理程序或 effect 中调用多个状态设置器,React 通常会将这些更新批处理在一起,以进行单次重新渲染,从而获得更好的性能。因此,您不应该依赖状态变量在调用设置器后立即具有新值。如果新状态依赖于之前的状态,请使用函数式更新形式
4742

4843
```javascript
49-
this.setState({ count: this.state.count + 1 }, () => {
50-
console.log('状态已更新,组件已重新渲染');
51-
});
44+
// 假设 count 为 0
45+
setCount(count + 1); // 将更新排队到 1
46+
setCount(count + 1); // 仍然将 count 视为 0,再次将更新排队到 1!
47+
// 结果可能是 1,而不是 2
48+
49+
// 使用函数式更新的正确方法:
50+
setCount((prevCount) => prevCount + 1); // 根据之前的状态将更新排队
51+
setCount((prevCount) => prevCount + 1); // 根据第一个的结果将另一个更新排队
52+
// 结果将是 2
5253
```
5354

5455
## 延伸阅读
5556

56-
* [React setState 文档](https://react.dev/reference/react/useState#setstate)
57-
* [理解 React 中的 setState](https://medium.com/@baphemot/understanding-react-setstate-a4640451865b)
58-
* [React 的 setState 解释](https://daveceddia.com/where-fetch-data-componentwillmount-vs-componentdidmount/)
57+
* [React 文档:使用状态 Hook (`useState`)](https://react.dev/reference/react/useState)
58+
* [React 文档:将多个状态更新排队](https://react.dev/reference/react/useState#updating-state-based-on-the-previous-state)

questions/explain-what-react-hydration-is/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"b473e52c",
2525
"13518d3f",
2626
"1f4770e5",
27-
"4cea244a"
27+
"dab0684e"
2828
]
2929
},
3030
"targets": {
@@ -47,7 +47,7 @@
4747
"b473e52c",
4848
"13518d3f",
4949
"1f4770e5",
50-
"4cea244a"
50+
"dab0684e"
5151
]
5252
}
5353
}

questions/explain-what-react-hydration-is/zh-CN.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ React 水合是在客户端附加事件监听器并使服务器渲染的 HTML
6666

6767
## 延伸阅读
6868

69-
* [React 水合文档](https://react.dev/reference/react-dom/client/hydrateRoot)
70-
* [React 中的服务器端渲染](https://react.dev/reference/react-dom/server)
71-
* [Next.js 水合文档](https://nextjs.org/docs/basic-features/pages#hydration)
69+
* [React 文档关于 hydration](https://react.dev/reference/react-dom/client/hydrateRoot)
70+
* [React 中的服务端渲染](https://react.dev/reference/react-dom/server)
71+
* [Next.js 文档关于 hydration](https://nextjs.org/docs/basic-features/pages#hydration)

questions/how-do-you-debug-react-applications/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"29b74665",
3131
"6663cd19",
3232
"1f4770e5",
33-
"f0c73459"
33+
"6a2e13c"
3434
]
3535
},
3636
"targets": {
@@ -59,7 +59,7 @@
5959
"29b74665",
6060
"6663cd19",
6161
"1f4770e5",
62-
"f0c73459"
62+
"6a2e13c"
6363
]
6464
}
6565
}

questions/how-do-you-debug-react-applications/zh-CN.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function MyComponent() {
139139

140140
## 延伸阅读
141141

142-
* [React 开发者工具](https://react.dev/learn/react-developer-tools)
143-
* [React 中的错误边界](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)
144-
* [使用 Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools)
145-
* [调试 JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging)
142+
* [React Developer Tools](https://react.dev/learn/react-developer-tools)
143+
* [Error boundaries in React](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)
144+
* [Using the Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools)
145+
* [Debugging JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging)

questions/how-do-you-decide-between-using-react-state-context-and-external-state-managers/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"e2b36f0b",
3030
"8d62a5c5",
3131
"1f4770e5",
32-
"b0c27fdc"
32+
"42c2150d"
3333
]
3434
},
3535
"targets": {
@@ -57,7 +57,7 @@
5757
"e2b36f0b",
5858
"8d62a5c5",
5959
"1f4770e5",
60-
"b0c27fdc"
60+
"42c2150d"
6161
]
6262
}
6363
}

questions/how-do-you-handle-asynchronous-data-loading-in-react-applications/en-US.langnostic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"2945cbb3",
2626
"25aeafcd",
2727
"1f4770e5",
28-
"aa577b63"
28+
"80b0b37f"
2929
]
3030
},
3131
"targets": {
@@ -49,7 +49,7 @@
4949
"2945cbb3",
5050
"25aeafcd",
5151
"1f4770e5",
52-
"aa577b63"
52+
"80b0b37f"
5353
]
5454
}
5555
}

0 commit comments

Comments
 (0)