Venkat
Venkat

Reputation: 371

Redux state is not updated Issue. But redux logger shows the correct action and next state update

I am using Redux for my web application. State has to be updated after user login. Redux logger is used for debugging. Everything is fine in redux logger but state is not updated. Please give any idea about this issue.

Reducers:

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;
    }
}

CombineReducers:

const rootReducer = combineReducers({
  authentication,
  registration,
  users,
  alert,
  adminReducers
});

export default rootReducer;

mapStateToProps: (In this console.log shows empty for all objects)

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 };

Accessing state in after login page, but shows empty for adminReducers:

enter image description here

Redux logger: (show that adminReducers in state is updated)

enter image description here

     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 

Upvotes: 1

Views: 380

Answers (0)

Related Questions