# React-0907
**Repository Path**: kingupdow/react-0907
## Basic Information
- **Project Name**: React-0907
- **Description**: React-router&redux学习
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-04-28
- **Last Updated**: 2023-04-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
##### Redux
1.什么是 Redux
```
redux是一个专门做状态管理的js库(不是react插件库)
它可以用在react,angular,vue等项目中,但基本与react配合使用
作用:集中式管理react应用中多个组件共享状态
```
2.什么时候需要使用 Redux
```
你在应用程序的许多地方都需要大量的应用程序状态
应用状态更新频繁
更新该状态的逻辑可能很复杂
该应用程序有一个中型或大型的代码库,并且可能由许多人开发
你需要查看该状态如何随着时间的推移而更新
```
3.怎么使用 Redux
```javascript
1、安装react-redux && redux-toolkit
yarn add react-redux redux-toolkit
2.创建store仓库 // src/store/index.ts 使用configureStore函数
import { configureStore } from "@reduxjs/toolkit";
import countSlice from './count/countSlice'
export default configureStore({
reducer: {
countSlice
}
})
3.使用redux // src/index.ts
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { Provider } from "react-redux"; // 引入react-redux的Provider跟组件
import store from "./store/index" // 引入store仓库
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(