当前位置:网站首页>Application of store Redux in project
Application of store Redux in project
2022-07-27 05:40:00 【My name is Lili】
First step
stay index Created in store
Front end data is migrated to the back end utilize react-redux
Created store use Provider Labels wrap all components and provide store
Put... In other components state The status moves to store In the middle
The second step Enhanced status
Then apply in the component mapState hold store The values in are mapped to Regist On the body jmapState Receive one state Parameters use ...stste.user Get values mapped to props Inside
The third step Enhancement method
use mapDispatch The act of distributing receive dispatch Parameters Execution method distributed dispatch To trigger action
At the same time, create another one that is only related to users user action Export a function userFiledUpdate The receiving parameters are key and value
And then put user action Import to the registration component and use dispatch To receive action There's a userFiledUpdate() attribute
Such as this :onEmailChange:(key,value)=>dispatch(action.userFiledUpdate(key,value))
And then through connect hold React Add these two attributes to the component
export default connect(mapState,mapDispatch) (Regist)
Step four Use store Value reducers Medium USER.JS
Pass in the method this.props Get mapdispatch Medium trigger action Methods { Actually... Here key value Namely action}
By sending with constants action If your constant is consistent with me user The defined constant is then store in user reducer The meeting of return down Conduct
key Dynamic values Do the mapping state Overwrite modification (...state,[key]:value) Take what you pass Email password user name
Step five : The registration has been written Next write to submit the registered
The submit button has a method , And then again dispatch This method is defined in , Through the onsubimt Trigger this method , Then distribute it in the same way action, Trigger action Then execute Asynchronous network request Then encapsulate a request
It says get post put delete Method
And then encapsulate a dedicated user user-requested request, Such as this
regist:(user)=>apiClient.post('/users',{user}),
In this way, the current end accesses /users When , The backend will also access the backend's routing address users Returns the status value status
If it is equal to 1 Status code Then jump to the login page .
Step seven : Add one more RESULT Constant Then you can query the error object when the constant does not match , And return error messages
Step eight : Every page has a dough cycle To realize the registration jump, the registration information should be refreshed after login
Implementation steps :
1: Define a life cycle Operate in this cycle before leaving this page , perform onUnload()
componentWillUnmount(){
this.props.onUnload()
}
I also buy you to enhance this method on this side , And then use dispatch Trigger action ( At the same time define a unload Constants allow you to enter ruderx Inside ) Then re initialize state Behavior , That's all right.
Here you can jump to the login page intact .
边栏推荐
- C语言指针入门详细介绍
- JS==操作符的强制类型转换规定
- 背景图片相关应用-铺满,自适应
- 初识C语言——初识指针
- map结构
- [BJDCTF2020]EasySearch 1
- Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
- js中isNaN和Number.isNaN的区别
- OSI七层模型和TCP/IP四层(TCP与UDP)(笔记)
- 下载url-loader,用limit指定图片大小后,显示不出图片
猜你喜欢
随机推荐
一本通1329 细胞(广度优先搜索)
一本通1319——排队接水
初识C语言——为什么每个C程序都有一个main函数
Trying to evolve_ My first CSDN blog
分享一道关于程序编译过程的选择题(内含编译过程浅谈,符号表的形成合并过程)
while循环
权限的配置,组件传值
每周学习总结
[codeworks round 801 div2 D tree queries] tree greedy conclusion
Apache SSI 远程命令执行漏洞
思考一些文件的作用
JS中如何判断一个属性是属于实例对象还是继承于构造函数
深度优先搜索(dfs)简介
arguments
JS如何判断一个对象是否属于一个类
Introduction to C language pointer
[MRCTF2020]PYWebsite 1
JS中&&(与)和||(或)操作符的返回值
MD5 password encryption
初始C语言——关键字static的作用



![[NPUCTF2020]ReadlezPHP 1](/img/d9/590446b45f917be3f077a9ea739c20.png)



![[网鼎杯 2020 朱雀组]Nmap 1两种解法](/img/fa/b1349cb42b5768b7510217239ba73a.png)

