1

我正在为我的 Web 应用程序使用 Redux。用户登录后必须更新状态。Redux logger 用于调试。redux 记录器中的一切都很好,但状态没有更新。请提供有关此问题的任何想法。

减速机:

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:(在此 console.log 中显示所有对象为空)

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 
4

0 回答 0