【发布时间】:2019-07-06 20:33:23
【问题描述】:
我已经在我的 redux reducer 中设置了登录身份验证的初始状态。成功登录时说 authError=null 我想更改它。当我点击注销时,我想设置authError = ''。
我可以将reducer从一个组件更改为只读状态吗?
组件
const {authError} = this.props;
this.setState(authError = "")
减速器
const initState = {
authError : '',
empname : 'test', phoneno:'321'
}
const signin = (state = initState, action) => {
switch(action.type){
case 'SIGN_IN':
const empname = action.payload.empname;
const phoneno = action.cred.phoneno;
console.log('===============$$$=====================');
console.log(empname, phoneno);
console.log('===============$$$=====================');
return {
...state,
authError : null,
empname,
phoneno
}
}
【问题讨论】:
-
reducer 的只读状态是什么意思?
标签: reactjs react-redux