当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Maintain login and route jump

First knowledge of C language - string + escape character + comment
![[网鼎杯 2020 朱雀组]Nmap 1两种解法](/img/fa/b1349cb42b5768b7510217239ba73a.png)
[网鼎杯 2020 朱雀组]Nmap 1两种解法

Pytorch installation new pit

Configure the route and go to the login home page to send the request

一本通1201——斐波那契数列

编辑删除用户

beef-xss安装与使用

Initial C language -- the function of keyword static

First knowledge of C language - why does every C program have a main function
随机推荐
[CISCN2019 华东南赛区]Web11 1
Dnsmasq Usage Summary
Introduction to C language functions
Page configuration
[BJDCTF2020]EasySearch 1
C语言进制转换以及原补反码位运算介绍
一本通1201——斐波那契数列
[C language switch branch statement and loop statement]
2021 Niuke multi school training camp 5 (question b)
云E办项目之部门管理
First knowledge of C language - string + escape character + comment
流程控制-分支
Source code of document type full-text retrieval knowledge base management system
eval与assert执行一句话木马
维持登录,路由跳转
一本通顺序结构程序设计题解(第一章)
cmd命令和npm命令
Promise的理解,以及它的实例方法
JS中forEach和map方法有什么区别
权限展示-左侧列表动态化