当前位置:网站首页>Redux usage
Redux usage
2022-07-08 01:38:00 【It's a fish, a small meatball, a duck】
Catalog
3.redux Conceptual understanding
4. establish Redux Warehouse in -store and reducer
5.redux middleware ( Redux-thunk)
1,redux workflow
2. install redux
npm i redux --save
3.redux Conceptual understanding
redux It is a special tool for state management js library ( No react Plug-in library )
Can be used in react,angular,vue In the project , Basic and react In combination with
effect : Centralized management react The state shared by multiple components in the application
4. establish Redux Warehouse in -store and reducer
First , Create a store Folder , And then create a index.js file , Create another reducer.js file
import { createStore } from "redux";
// introduce reducer file
import reducer from './reducer'
let store=createStore(reducer)
export default store
reducer.js file
const defaultState={
value:‘ Zhang San ’,
list:[
' Hello! ',
'hello'
]
}
// Business logic can be written here
export default (state=defaultState,action)=>{
return state
}
such , ordinary store and reducer Just set it up , Now we use store Warehouse
First, introduce
import store from './store'
Then we can print it store, The results are as follows , He has one getState() Method
Then render us on the page getState Just the value inside
notes :reducer receive calls only state, Can't change state
5.redux middleware ( Redux-thunk)
install
npm i redux-thunk --save
To configure
import { createStore,applyMiddleware } from "redux";
import thunk from 'redux-thunk'
// introduce reducer file
import reducer from './reducer'
let store=createStore(reducer,applyMiddleware(thunk))
export default store
creatStore Only two parameters can be received , If you want to define multiple parameters , We can use enhancement functions (compose)
Asynchronous processing is written in middleware Redux-thunk in
Resolve asynchrony action Out of commission function Method , If we don't use middleware , So if we are action Using functions in , Then he will report an error
6.combineReducers Use
effect : Merge multiple reducer function
redux Of combineReducers() It's convenient to put redux Of reducer Split into small reducer file , Call their own reducer, Convenient unified management
creatStore Only two parameters can be received , If you want to define multiple parameters , We can deal with many reduce A merger , Use combineReducers
import { createStore,applyMiddleware,combineReducers } from "redux";
import countReduce from '../reduces/count_reduce'
import todoReduce from '../reduces/todolist_reduce'
import thunk from 'redux-thunk'
// Use redux Officially provided merger reduce Method
const allReducer = combineReducers({
count:countReduce,
todolist:todoReduce
})
// The first parameter is all reduce, The second parameter is to support asynchronous action Middleware
let store = createStore(allReducer,applyMiddleware(thunk))
export default store
边栏推荐
- The usage of rand function in MATLAB
- 2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills
- 2021 welder (primary) examination skills and welder (primary) operation examination question bank
- [loss function] entropy / relative entropy / cross entropy
- Gnuradio 3.9 using OOT custom module problem record
- 碳刷滑环在发电机中的作用
- break net
- Usage of xcolor color in latex
- Matlab code about cosine similarity
- Anaconda3 tutorial on installing and adding Tsinghua image files
猜你喜欢
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
QT -- package the program -- don't install qt- you can run it directly
4、策略學習
Understanding of maximum likelihood estimation
Working principle of stm32gpio port
ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
2021-03-14 - play with generics
生态 | 湖仓一体的优选:GBase 8a MPP + XEOS
The combination of relay and led small night light realizes the control of small night light cycle on and off
随机推荐
Matlab code about cosine similarity
break algorithm---刷题map
2022 high voltage electrician examination skills and high voltage electrician reexamination examination
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination
NPM internal split module
2022 high altitude installation, maintenance and demolition examination materials and high altitude installation, maintenance and demolition operation certificate examination
3. Multi agent reinforcement learning
Leetcode notes No.21
第七章 行为级建模
2、TD+Learning
QT build with built-in application framework -- Hello World -- use min GW 32bit
5. Contrôle discret et contrôle continu
Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
php 获取音频时长等信息
小金额炒股,在手机上开户安全吗?
Redis 主从复制
Problems of font legend and time scale display of MATLAB drawing coordinate axis
Understanding of prior probability, posterior probability and Bayesian formula
ROS problems (topic types do not match, topic datatype/md5sum not match, MSG XXX have changed. rerun cmake)
MySQL数据库(2)