Skip to main content

API 参考

¥API Reference

本节记录了原始 Redux 核心 API。Redux 核心很小 - 它定义了一组供你实现的合约(例如 reducers),并提供了一些辅助函数将这些合约绑定在一起。

¥This section documents the original Redux core API. The Redux core is small - it defines a set of contracts for you to implement (such as reducers) and provides a few helper functions to tie these contracts together.

在实践中,你不会直接使用 Redux 核心。Redux 工具包 是我们官方推荐的编写 Redux 逻辑的方法。它围绕 Redux 核心,并包含我们认为构建 Redux 应用所必需的包和函数。Redux Toolkit 构建了我们建议的最佳实践,简化了大多数 Redux 任务,防止常见错误,并使编写 Redux 应用变得更加容易。此外,React-Redux 还允许你的 React 组件与 Redux 存储进行通信。

¥In practice, you won't use the Redux core directly. Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications. Additionally, React-Redux lets your React components talk to the Redux store.

请在此处查看他们的 API 文档:

¥See their API docs here:

危险

原来的 Redux core createStore 方法已被弃用!

¥The original Redux core createStore method is deprecated!

createStore 将无限期地继续工作,但我们不鼓励直接使用 createStore 或原始 redux 包。

¥createStore will continue to work indefinitely, but we discourage direct use of createStore or the original redux package.

相反,你应该使用我们官方 Redux 工具包 包中的 configureStore 方法,它封装了 createStore 以提供更好的默认设置和配置方法。你还应该使用 Redux Toolkit 的 createSlice 方法 来编写 reducer 逻辑。

¥Instead, you should use the configureStore method from our official Redux Toolkit package, which wraps createStore to provide a better default setup and configuration approach. You should also use Redux Toolkit's createSlice method for writing reducer logic.

Redux Toolkit 还重新导出 redux 包中包含的所有其他 API。

¥Redux Toolkit also re-exports all of the other APIs included in the redux package as well.

有关如何更新现有旧 Redux 代码库以使用 Redux Toolkit 的详细信息,请参阅 迁移到 Modern Redux 页面

¥See the Migrating to Modern Redux page for details on how to update your existing legacy Redux codebase to use Redux Toolkit.

顶层导出

¥Top-Level Exports

存储 API

¥Store API