diff --git a/beta/src/pages/learn/managing-state.md b/beta/src/pages/learn/managing-state.md index 57b79bf8e7..6fc6696fd9 100644 --- a/beta/src/pages/learn/managing-state.md +++ b/beta/src/pages/learn/managing-state.md @@ -1,30 +1,34 @@ --- -title: Managing State +title: 状态管理 +translators: + - qinhua + - KnowsCount + - QC-L --- -As your application grows, it helps to be more intentional about how your state is organized and how the data flows between your components. Redundant or duplicate state is a common source of bugs. In this chapter, you'll learn how to structure your state well, how to keep your state update logic maintainable, and how to share state between distant components. +随着你的应用不断变大,更有意识的去关注应用状态如何组织,以及数据如何在组件之间流动会对你很有帮助。冗余或重复的状态往往是缺陷的根源。在本节中,你将学习如何组织好状态,如何保持状态更新逻辑的可维护性,以及如何跨组件共享状态。 -* [How to think about UI changes as state changes](/learn/reacting-to-input-with-state) -* [How to structure state well](/learn/choosing-the-state-structure) -* [How to "lift state up" to share it between components](/learn/sharing-state-between-components) -* [How to control whether the state gets preserved or reset](/learn/preserving-and-resetting-state) -* [How to consolidate complex state logic in a function](/learn/extracting-state-logic-into-a-reducer) -* [How to pass information without "prop drilling"](/learn/passing-data-deeply-with-context) -* [How to scale state management as your app grows](/learn/scaling-up-with-reducer-and-context) +* [如何将 UI 变更视为状态变更](/learn/reacting-to-input-with-state) +* [如何组织好状态](/learn/choosing-the-state-structure) +* [如何使用“状态提升”在组件之间共享状态](/learn/sharing-state-between-components) +* [如何控制状态的保留或重置](/learn/preserving-and-resetting-state) +* [如何在函数中整合复杂的状态逻辑](/learn/extracting-state-logic-into-a-reducer) +* [如何避免数据通过 prop 逐级透传](/learn/passing-data-deeply-with-context) +* [如何随着应用的增长去扩展状态管理](/learn/scaling-up-with-reducer-and-context) -## Reacting to input with state {/*reacting-to-input-with-state*/} +## 使用状态响应输入 {/*reacting-to-input-with-state*/} -With React, you won't modify the UI from code directly. For example, you won't write commands like "disable the button", "enable the button", "show the success message", etc. Instead, you will describe the UI you want to see for the different visual states of your component ("initial state", "typing state", "success state"), and then trigger the state changes in response to user input. This is similar to how designers think about UI. +使用 React,你不用直接从代码层面修改 UI。例如,不用编写诸如“禁用按钮”、“启用按钮”、“显示成功消息”等命令。相反,你只需要描述组件在不同状态(“初始状态”、“输入状态”、“成功状态”)下希望展现的 UI,然后根据用户输入触发状态更改。这和设计师对 UI 的理解很相似。 -Here is a quiz form built using React. Note how it uses the `status` state variable to determine whether to enable or disable the submit button, and whether to show the success message instead. +下面是一个使用 React 编写的反馈表单。请注意看它是如何使用 `status` 这个状态变量来决定启用或禁用提交按钮,以及是否显示成功消息的。 @@ -37,7 +41,7 @@ export default function Form() { const [status, setStatus] = useState('typing'); if (status === 'success') { - return

That's right!

+ return

答对了!

} async function handleSubmit(e) { @@ -58,9 +62,9 @@ export default function Form() { return ( <> -

City quiz

+

城市测验

- In which city is there a billboard that turns air into drinkable water? + 哪个城市有把空气变成饮用水的广告牌?