type
status
date
slug
summary
tags
category
password
React JS 上手
1:阅读前须知
阅读前需要知道的一些事
1:前面有 Vue 框架的经验,此文可以带你快速上手 React JS 作为拓展技术栈
2:学过 HTML / CSS / JS 想直接上手框架,那么我们这篇文章也可以带你直接入手 React
3:后端开发,想做全栈的,可以通过本文章学习 React 作为前端技术栈的第一个框架
2:技术栈
经典企业级技术栈
React 18
Redux
ReactRouter
AntD
Zustand(扩展)
TypeScript(扩展)
3:React 基础
3.1:React 是什么
3.2:React 的优势
3.3:React 开发环境


3.4:React JSX 基础

3.5:React JSX 进阶







3.6:React 事件绑定




3.7:React 组件


3.8:React Hooks(useState)



3.9:React 组件基础样式

3.10:React classnames 库使用

3.11:React 受控表单绑定


3.12:React 获取 DOM



3.13:阶段测试(完善评论区小项目)
3.14:React 父子传递


3.15:React 子父传递

3.16:React 兄弟组件通信

3.17:React Context 跨层通信

3.18:React useEffect 组件

依赖项 | 副作用函数执行时机 |
没有依赖项 | 组件初始化渲染 + 组件更新时执行 |
空数组依赖项 | 只在初始渲染时执行一次 |
添加特定依赖项 | 组件初始渲染 + 特性依赖项变化时执行 |






3.19:React 实现自定义 Hook


3.20:React 自定义 Hook 的使用规则
3.21:阶段测试(完善评论区小项目)
4:Redux 快速上手
4.1:Redux 是什么


4.2:React 使用 Redux






4.3:Redux 与 React 异步状态操作


5:React Router 快速上手
5.1:React Router 是什么



5.2:React Router 抽象路由模块



5.3:React Router 路由导航


5.3:React Router 路由导航跳转传参




5.4:React Router 嵌套路由配置



5.5:React Router 默认二级路由配置

5.6:React Router 404 路由设置

5.7:React Router 的常见的路由模式
路由模式 | URL 表现 | 底层原理 | 是否需要后端能支持 |
history | url/login | history 对象 + pushState 事件 | 需要 |
hash | url/#/login | 监听 hashChange 事件 | 不需要 |



6:综合案例 - 文章管理平台
6.1:初始化项目 + 配置 Vite 和目录
目录 | 作用 |
apis | 接口 |
assets | 静态资源 |
components | 通用组件 |
pages | 页面级组件 |
router | 路由 Router |
store | Redux 状态 |
utils | 工具函数 |
6.2:接入 sass 兼容 scss 文件

6.3:安装 Ant Design 组件库

6.4:配置基础路由 Router
6.5:构建登录页面


6.6:登录表单校验实现



6.7:获取表单数据

6.8:封装 request 请求模块

6.9:使用 Redux 管理 Token
6.10:实现 Token 异步获取


6.11:登录逻辑实现
6.12:Token 持久化


6.13:封装 Token 的存取方法
6.14:Axios 请求头注入 Token

6.15:根据 Token 做路由权限控制
6.16:Layout 结构布局与样式初始化

6.17:Layout 二级路由配置
6.18:点击菜单时触发跳转路由
6.19:根据路由路径高亮菜单
6.20:个人信息展示



6.21:退出登录实现


6.22:Token 失效问题处理
6.23:Apache ECharts 使用


6.24:Apache ECharts 组件封装


6.25:API 模块封装


6.26:文章发布功能实战开发



6.27:文章列表和删除功能开发




6.28:文章更新功能实现


6.29:项目打包与本地预览

6.30:项目打包优化







7:扩展知识
7.1:useReducer


7.2:useMemo


7.3:React.memo


7.4:React.memo props 比较机制


7.5:useCallback


7.6:forwardRef


7.7:useImperativeHandle

8:zustand
8.1:zustand 快速上手


8.2:zustand 异步支持

8.3:zustand 切片模式

9:TypeSscript 基础扩展
9.1:基础环境搭建

9.2:useState 自动推导





9.3:useState 泛型参数

9.4:useState 初始值为 null

9.5:TS 与 Props - 基础使用


9.6:TS 与 Props - 为 children 添加类型

9.7:TS 与 Props - 为事件 prop 添加类型

9.8:TS 与 useRef - 获取 DOM
9.9:TS 与 useRef - 引用稳定的存储器

- 作者:Gitlayzer
- 链接:https://www.devops-engineer.com.cn/article/react_notes
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。