当前位置:网站首页>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 --save3.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 storereducer.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 storecreatStore 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边栏推荐
- Different methods for setting headers of different pages in word (the same for footer and page number)
- Understanding of sidelobe cancellation
- Redis 主从复制
- php 获取音频时长等信息
- LaTeX 中 xcolor 颜色的用法
- common commands
- 2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
- Micro rabbit gets a field of API interface JSON
- Is it safe to open an account on your mobile phone for small amount of stock speculation?
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
猜你喜欢

子矩阵的和

Different methods for setting headers of different pages in word (the same for footer and page number)

The communication clock (electronic time-frequency or electronic time-frequency auxiliary device) writes something casually

Understanding of expectation, variance, covariance and correlation coefficient

从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值

STM32GPIO口的工作原理

MATLAB R2021b 安装libsvm

用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟

About snake equation (5)

4、策略学习
随机推荐
Talk about smart Park
Qt - - Packaging Programs - - Don't install Qt - can run directly
break algorithm---刷题map
Mat file usage
5. Contrôle discret et contrôle continu
Anaconda3 download address Tsinghua University open source software mirror station
用户之声 | 对于GBase 8a数据库学习的感悟
MySQL数据库(2)
Application of state mode in JSF source code
解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
快速熟知XML解析
LaTeX 中 xcolor 颜色的用法
Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
Gnuradio3.9.4 create OOT module instances
The beauty of Mathematics -- the principle of fine Fourier transform
Redis master-slave replication
Apt get error
Smart agricultural technology framework
Matlab code on error analysis (MAE, MAPE, RMSE)
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)