Redux reducer没有显示我的控制台日志,并返回未定义



嗨,自从我将JWT添加到我的嵌套API后,我的Redux应用程序出现了问题,这是我的减速器的代码:

export default function reducer(state = {}, action) {
switch (action.type) {
case 'USER_LOGIN_SUCCESS':
console.log('USER_LOGIN_SUCCESS')
return action.payload.user;
case 'USER_REGISTER_SUCCESS':
// user exist
if(action.payload.status === 409){
console.log(action.payload)
return state;
}
console.log(action.payload)
return state
case 'USER_REGISTER_FAILURE':
case 'USER_LOGIN_FAILURE':
default:
console.log('lol');
return state
}
}

当我用redux-API-midleware登录到我的API时,这就是我在控制台中得到的:

redux.js:463 Uncaught (in promise) Error: Given action "USER_LOGIN_SUCCESS", reducer "user" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.
at combination (redux.js:463)
at dispatch (redux.js:213)
at _callee$ (index.umd.js:2874)
at s (index.js:1)
at Generator._invoke (index.js:1)
at Generator.e.<computed> [as next] (index.js:1)
at asyncGeneratorStep (index.umd.js:33)
at _next (index.umd.js:55)

当我向POSTMAN尝试我的请求时,它非常成功:/问题是它甚至没有在我的reducer案例中显示console.log:"USER_LOGIN_SCCESS">

以下是POSTMAN上的请求回复:邮递员响应

USER_LOGIN_SUCCESS的情况下,您将返回操作有效载荷值。

使用reducer,您必须始终返回状态对象或状态对象的不可变副本。

目前还不清楚reducer状态对象是什么样子的,但我认为它包含一个用户属性

return {
...state,
user: action.payload.user
}

最新更新