react-redux README

The project's README from github.com/reduxjs/react-redux. As one markdown file: README.md.

React Redux

Official React bindings for Redux. Performant and flexible.

GitHub Workflow Status npm version npm downloads #redux channel on Discord

Installation

Create a React Redux App

The recommended way to start new apps with React and Redux is by using our official Redux+TS template for Vite, or by creating a new Next.js project using Next's with-redux template.

Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.

# Vite with our Redux+TS template
# (using the `degit` tool to clone and extract the template)
npx degit reduxjs/redux-templates/packages/vite-template-redux my-app

# Next.js using the `with-redux` template
npx create-next-app --example with-redux my-app

An Existing React App

React Redux 9.0 requires React 18 or later

To use React Redux with your React app, install it as a dependency:

# If you use npm:
npm install react-redux

# Or if you use Yarn:
yarn add react-redux

You'll also need to install Redux and set up a Redux store in your app.

This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.

If you don’t yet use npm or a modern module bundler, and would rather prefer a single-file UMD build that makes ReactRedux available as a global object, you can grab a pre-built version from cdnjs. We don’t recommend this approach for any serious application, as most of the libraries complementary to Redux are only available on npm.

Documentation

The React Redux docs are published at https://react-redux.js.org .

How Does It Work?

The post The History and Implementation of React-Redux explains what it does, how it works, and how the API and implementation have evolved over time.

There's also a Deep Dive into React-Redux talk that covers some of the same material at a higher level.

License

MIT

react-redux (reduxjs/react-redux)

Searching Database…

这是什么?这是 Redux 的官方 React 绑定库,作用是把你的 React 组件连接到 Redux store,让组件能够读取状态并派发 action。
它是 Redux 本身,还是需要额外加装的东西?它是一个库,不是 Redux 本身。你需要把它和 Redux 一起安装,由它负责 React 这边的连接工作,让组件订阅你的 store。
怎么把它加到现有的 React 应用里?运行 npm install react-redux,然后安装 Redux 并在你的应用里配置好 store。它默认你使用 npm,并搭配 Webpack 或 Browserify 这类模块打包工具。
它和我的 React 版本兼容吗?React Redux 9.0 要求 React 18 或更高版本。这个包本身很小:运行时唯一的依赖是 use-sync-external-store,并且自带 TypeScript 类型。
能不能只用一个 script 标签从 CDN 引入?cdnjs 上有预构建的 UMD 版本,会暴露一个全局的 ReactRedux 对象,但 README 不建议在正式项目中这样做,因为大多数配套的 Redux 库只能通过 npm 安装。
用它新建一个项目,推荐怎么做?使用官方的 Redux+TS 模板创建 Vite 项目,或者用 with-redux 模板创建 Next.js 项目。这两种方式都会预先配置好 Redux Toolkit 和 React-Redux,还附带一个小示例应用。
在哪里可以了解它的底层原理?《History and Implementation of React-Redux》这篇文章介绍了它的功能,以及 API 和实现是如何逐步演变的。另有一个 Deep Dive 演讲以更高的层面讲述了同样的内容。
这个项目还在积极维护吗?是的——它位于官方的 reduxjs GitHub 组织下,创建于 2015 年,有超过 23k 的 star,没有被归档,仓库里还配有用于测试、构建和发布的 CI 工作流。
Creator
reduxjs
Size
14.4 MB
Stars
23.4K
Age
11y
Commits · 90 Days