传递给createStore的preloadedState参数具有意外类型" Null"。预期参数为具有以下键的对象:"登录"

时间:2017-02-04 11:41:07

标签: javascript reactjs react-native

伙计们,我在调试我最近在我的应用程序中遇到的错误时遇到了问题 " createStore的preloadedState参数具有意外类型的Null.Expected参数,它是一个带有填充键的对象:" login""

这是一个reducer文件代码片段,它导出combinedReducers

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

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

export default combineReducers({
  login
});

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

和Login Reducer代码段看起来像

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

};

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

和商店

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

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

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

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

export default store;

======================== 请帮帮我们..

1 个答案:

答案 0 :(得分:1)

你可以传递和清空对象。

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