Redux Study-- Source Code

Intro

This study base on the 4.0.4 version of Redux, which is implemented by TypeScript.

index.ts

The entrance of the codes, providing all the components API.

isCrushed() used to discover current environment is developing or production environment .

if the code is compressed and under production environment , then isCrushed.name will be type of String but the name will be changed to others

React-Redux 学习笔记

First of All

Redux并不是全局state管理唯一的方案,基于开发不同的工程,我们可以选择三种方案来解决props传递的问题。

  1. Hook
  2. React Context API
  3. and Redux

store

​ store 是本地state的集合,操作的state的都在里面,本地state指的是组件及其子组件的state.

reducer

​ reducer干的事很简单, 拿到一个state 和一个action返回 newstate

​ 我们可以总结为一个arrow funciton:

1
(state,action) => newState

reducer 需要一个初始状态,并且我们需要确保reducer在任何状态下都有state,缺失state的reducer是非常差劲的写法,初始状态示意如下

1
2
3
const initialState = {
something:0,
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×