我正在将Redux用于我的Web应用程序。用户登录后必须更新状态。 Redux记录器用于调试。在redux logger中一切正常,但状态未更新。请提供有关此问题的任何想法。
减速器:
import { adminConstants } from '../Admin/admin.constants.js';
export function adminReducers(state={},action)
{
switch (action.type) {
case adminConstants.ADMIN_LOGIN_REQUEST:
return {
loggingIn: true,
};
case adminConstants.ADMIN_LOGIN_SUCCESS:
return {
loggedIn: true,
admin:action.admin
};
case adminConstants.ADMIN_LOGIN_FAILURE:
return {};
case adminConstants.ADMIN_LOGOUT:
return {};
default:
return state;
}
}
组合还原剂:
const rootReducer = combineReducers({
authentication,
registration,
users,
alert,
adminReducers
});
export default rootReducer;
mapStateToProps :(在此控制台中,所有对象的日志均显示为空)
function mapStateToProps(state) {
console.log("state "+ JSON.stringify(state));
const { adminReducers } = state;
const { admin } = adminReducers;
return {
admin
};
}
const connectedAdminPanel = connect(mapStateToProps)(AdminPanel);
export { connectedAdminPanel as AdminPanel };
登录页面后的访问状态为,但对于adminReducers则显示为空:
Redux记录器:(显示处于状态的adminReducers已更新)
action AD_LOGIN_REQUEST @ 07:43:40.601
redux-logger.js:400 prev state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {}__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
redux-logger.js:404 action {type: "AD_LOGIN_REQUEST", admin: {…}}admin: {adminname: "iamadmin"}adminname: "iamadmin"__proto__: Objecttype: "AD_LOGIN_REQUEST"__proto__: Object
redux-logger.js:413 next state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {loggingIn: true}loggingIn: true__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
Admin.js:36 Log store {"authentication":{},"registration":{},"users":{},"alert":{},"adminReducers":{"loggingIn":true}}
admin.service.js:25 200
redux-logger.js:389 action AD_LOGIN_SUCCESS @ 07:43:40.645
redux-logger.js:400 prev state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {loggingIn: true}loggingIn: true__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
redux-logger.js:404 action {type: "AD_LOGIN_SUCCESS", admin: {…}}admin: {_id: "5c68451200801fc955188527", aname: "iamadmin", password: "removed", hash: "$2a$10$rDvt9fKK8mfymbKREdtILO6SneFQBllD9r/5xBHX.ynrt0Vt0u5.6", token: "removed"}type: "AD_LOGIN_SUCCESS"__proto__: Object
redux-logger.js:413 next state