redux的使用
依賴包
react-redux
redux
redux-thunk
@reduxjs/toolkit
@types/react-redux
store目錄

工作過程
dispatch派發action,拿到action返回的對象,這個對象上有actionType和新的state
接下來redux會自己觸發reducer,根據actionType匹配到要修改的state,修改state后返回一個新的state
理解action
action只要return出來一個帶actionType和新state的對象就ok
理解reducer
每個reducer都返回一個新的state
用法
index.ts
下圖中 root和task是reducer,整合reducer時combineReducers接收的參數名就是你的state

組件中獲取state

組件中派發action




浙公網安備 33010602011771號