Skip to content

Commit

Permalink
fix typo in extracting-state-logic-into-a-reducer.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Aries-0331 committed Mar 12, 2024
1 parent 67de09b commit 7fccfab
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/content/learn/extracting-state-logic-into-a-reducer.md
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ Reducers 并非没有缺点!以下是比较它们的几种方法:

编写 `reducers` 时最好牢记以下两点:

* **reducers 必须是纯粹的。** 这一点和 [状态更新函数](/learn/queueing-a-series-of-state-updates) 是相似的,`reducers` 在是在渲染时运行的!(actions 会排队直到下一次渲染)。 这就意味着 `reducers` [必须纯净](/learn/keeping-components-pure),即当输入相同时,输出也是相同的。它们不应该包含异步请求、定时器或者任何副作用(对组件外部有影响的操作)。它们应该以不可变值的方式去更新 [对象](/learn/updating-objects-in-state)[数组](/learn/updating-arrays-in-state)
* **reducers 必须是纯粹的。** 这一点和 [状态更新函数](/learn/queueing-a-series-of-state-updates) 是相似的,`reducers` 是在渲染时运行的!(actions 会排队直到下一次渲染)。 这就意味着 `reducers` [必须纯净](/learn/keeping-components-pure),即当输入相同时,输出也是相同的。它们不应该包含异步请求、定时器或者任何副作用(对组件外部有影响的操作)。它们应该以不可变值的方式去更新 [对象](/learn/updating-objects-in-state)[数组](/learn/updating-arrays-in-state)
* **每个 action 都描述了一个单一的用户交互,即使它会引发数据的多个变化。** 举个例子,如果用户在一个由 `reducer` 管理的表单(包含五个表单项)中点击了 `重置按钮`,那么 dispatch 一个 `reset_form` 的 action 比 dispatch 五个单独的 `set_field` 的 action 更加合理。如果你在一个 `reducer` 中打印了所有的 `action` 日志,那么这个日志应该是很清晰的,它能让你以某种步骤复现已发生的交互或响应。这对代码调试很有帮助!

## 使用 Immer 简化 reducers {/*writing-concise-reducers-with-immer*/}
Expand Down

0 comments on commit 7fccfab

Please sign in to comment.