最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - The preloadedState argument passed to createStore has unexpected type of "Null". Expected argumen

programmeradmin2浏览0评论

Guys i am having trouble debugging the error i have recently got in my application, which is "The preloadedState argument to createStore has unexpected type of Null.Expected argument to be an object with the fillowing keys: "login""

Here is a reducer file code snippet which export binedReducers

import {Map, fromJS} from 'immutable';
import {bineReducers} from 'redux';

import { login } from '../modules/login/LoginReducer';

export default bineReducers({
  login
});

======================================

AND THE Login Reducer code snippet looks like

import {
  AUTH_USER,
  SET_ADMIN_PRIVILEGES,
  AUTH_ERROR
} from './login.types';

const INITIAL_STATE = { errors: null, authenticated: false, admin_privileges: false };

export const login =  (state = INITIAL_STATE, action) => {
 switch(action.type) {
     case AUTH_USER:
            return { ...state, errors: null, authenticated: true };
        case SET_ADMIN_PRIVILEGES:
            return { ...state, admin_privileges: true };
         case AUTH_ERROR:
            return { ...state, errors: action.errors };
          default:
            return state;
 }

};

==============================

AND THE STORE

import {applyMiddleware, createStore, pose} from 'redux';
import * as reduxLoop from 'redux-loop';

import middleware from './middleware';
import reducer from './reducer';

const enhancer = pose(
  applyMiddleware(...middleware),
  reduxLoop.install()
);

// create the store
const store = createStore(
  reducer,
  null,
  enhancer
);

export default store;

======================== Please help guys..

Guys i am having trouble debugging the error i have recently got in my application, which is "The preloadedState argument to createStore has unexpected type of Null.Expected argument to be an object with the fillowing keys: "login""

Here is a reducer file code snippet which export binedReducers

import {Map, fromJS} from 'immutable';
import {bineReducers} from 'redux';

import { login } from '../modules/login/LoginReducer';

export default bineReducers({
  login
});

======================================

AND THE Login Reducer code snippet looks like

import {
  AUTH_USER,
  SET_ADMIN_PRIVILEGES,
  AUTH_ERROR
} from './login.types';

const INITIAL_STATE = { errors: null, authenticated: false, admin_privileges: false };

export const login =  (state = INITIAL_STATE, action) => {
 switch(action.type) {
     case AUTH_USER:
            return { ...state, errors: null, authenticated: true };
        case SET_ADMIN_PRIVILEGES:
            return { ...state, admin_privileges: true };
         case AUTH_ERROR:
            return { ...state, errors: action.errors };
          default:
            return state;
 }

};

==============================

AND THE STORE

import {applyMiddleware, createStore, pose} from 'redux';
import * as reduxLoop from 'redux-loop';

import middleware from './middleware';
import reducer from './reducer';

const enhancer = pose(
  applyMiddleware(...middleware),
  reduxLoop.install()
);

// create the store
const store = createStore(
  reducer,
  null,
  enhancer
);

export default store;

======================== Please help guys..

Share Improve this question edited Feb 4, 2017 at 13:10 Santosh Sharma 2,2481 gold badge18 silver badges30 bronze badges asked Feb 4, 2017 at 11:41 bikram basnetbikram basnet 1493 silver badges8 bronze badges 1
  • 1 If you don't want a preloaded state, you can just pass the enhancer as the second argument (redux will coalesce it) – PlantTheIdea Commented Feb 4, 2017 at 13:11
Add a ment  | 

1 Answer 1

Reset to default 7

You can just pass and empty object.

const initialState = {}    
const store = createStore(
    reducer,
    initial_state,
    enhancer
);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论