Skip to main content

学习资源

Redux 文档旨在教授 Redux 的基本概念,并解释在现实应用中使用的关键概念。然而,文档无法涵盖所有内容。幸运的是,有许多优秀的其他资源可用于学习 Redux。我们鼓励你去了解它们。许多资源涵盖了超出文档范围的话题,或者用不同的方式描述相同的话题,可能更适合你的学习风格。

本页包含我们推荐的一些最佳外部资源,用于学习 Redux。关于 React、Redux、JavaScript 及相关主题的更多教程、文章和资源详见 React/Redux 链接列表。

建议先学习这些教程

如果你刚接触 Redux,建议先从我们的教程开始。Redux Essentials 教程介绍如何使用 Redux Toolkit 和 React-Redux 构建真实应用;Redux Fundamentals 教程则从基础讲解 Redux 的工作原理。我们还有一个推荐视频页面。

下面有些文章发表于 Redux Toolkit 出现之前。我们已在相应位置注明。文章中的概念仍然适用,但代码示例采用的是较旧模式。

基础介绍​

教授 Redux 基本概念及其用法的教程

在 React 中使用 Redux​

解释 React-Redux 绑定库

TypeScript​

在 TypeScript 中使用 Redux

  • Redux:TypeScript 使用指南
    Usage with TypeScript
    我们编写的指南,介绍如何配置带类型的 store、hooks、slice 和 thunk。

  • Redux Toolkit:TypeScript 使用指南
    Quick Start
    Redux Toolkit: Usage with TypeScript
    快速开始教程介绍了带类型的 store 基础配置;Redux Toolkit 指南则逐一说明 RTK API 的类型用法。

使用 RTK Query 获取数据​

使用 Redux Toolkit 的 RTK Query API 获取并缓存服务器数据

Redux DevTools​

  • Redux DevTools
    https://github.com/reduxjs/redux-devtools
    Redux DevTools 浏览器扩展可检查每个已派发的 action 和状态变化,并在不同状态之间来回跳转。configureStore 会在开发环境自动启用它。仓库包含浏览器扩展、适用于 React Native 等环境的独立 @redux-devtools/cli,以及底层 DevTools 组件。

基于项目的教程​

通过构建项目教授 Redux 概念,包括较大的“真实世界”应用

  • 实用 Redux
    https://blog.isquaredsoftware.com/2016/10/practical-redux-part-0-introduction/
    https://blog.isquaredsoftware.com/series/practical-redux/
    A series of posts intended to demonstrate a number of specific Redux techniques by building a sample application, based on the MekHQ application for managing Battletech campaigns. Written by Redux co-maintainer Mark Erikson. Covers topics like managing relational data, connecting multiple components and lists, complex reducer logic for features, handling forms, showing modal dialogs, and much more. (Note: this is an older series, and today we recommend newer patterns for writing Redux code. However, many of the principles in this series are still valuable.)

Redux 实现​

通过编写简易重实现来解释 Redux 内部工作原理

Reducers​

探讨编写 reducer 函数的方法的文章

  • Structuring Reducers
    Structuring Reducers
    我们编写的指南,介绍如何拆分、组合和复用 reducer 逻辑、归一化状态以及采用不可变更新模式。Redux Toolkit 的 createSlice 也遵循这些模式。

  • Taking Advantage of combineReducers
    https://randycoulman.com/blog/2016/11/22/taking-advantage-of-combinereducers/
    展示多次使用 combineReducers 构造状态树的示例,并讨论不同 reducer 逻辑方案的取舍。这些思路同样适用于传给 configureStore 的 reducer 对象。

Selector​

解释为何以及如何使用 selector 函数从状态中读取值

  • Deriving Data with Selectors
    Deriving Data with Selectors
    我们编写的指南,介绍如何编写 selector、使用 Reselect 进行记忆化,以及如何与 React-Redux 配合使用。

  • Reselect docs
    https://redux.js.org/reselect/
    Reselect 官方文档,包括 createSelector API、记忆化选项,以及用于捕获常见 selector 错误的开发模式检查。

  • Idiomatic Redux: Using Reselect Selectors for Encapsulation and Performance
    https://blog.isquaredsoftware.com/2017/12/idiomatic-redux-using-reselect-selectors/
    A complete guide to why you should use selector functions with Redux, how to use the Reselect library to write optimized selectors, and advanced tips for improving performance. (Note: the code samples use connect, but the reasoning applies equally to useSelector.)

规范化 (Normalization)​

如何将 Redux store 结构化为类似数据库以获得最佳性能

中间件​

解释及示例讲解中间件如何工作及如何编写

副作用​

在 Redux 中处理异步行为

Thinking in Redux​

深入探究 Redux 的使用理念和设计原理

Redux 架构​

组织大型 Redux 应用的模式和实践

应用和示例​

Redux 文档翻译​

更多资源​

  • React-Redux 链接列表精选了关于 React、Redux、ES2015 等主题的优质文章、教程和相关内容。
  • Awesome Redux 收录了大量 Redux 相关仓库。
  • DEV Community 可用于分享 Redux 项目、文章和教程,发起讨论并征求相关反馈。欢迎各种经验水平的开发者参与。