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

bik*_*net 3 javascript reactjs react-native

伙计们,我在调试最近在我的应用程序中遇到的错误时遇到了麻烦,即“createStore 的 preloadedState 参数具有意外类型的 Null.Expected 参数是具有填充键的对象:“登录””

这是导出组合减速器的减速器文件代码片段

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

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

export default combineReducers({
  login
});
Run Code Online (Sandbox Code Playgroud)

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

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

};
Run Code Online (Sandbox Code Playgroud)

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

和商店

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;
Run Code Online (Sandbox Code Playgroud)

======================== 请大家帮忙..

小智 6

您可以只传递和清空对象。

const initialState = {}    
const store = createStore(
    reducer,
    initial_state,
    enhancer
);
Run Code Online (Sandbox Code Playgroud)

  • 这似乎与提出的问题没有任何关系 (2认同)
  • 实际上,答案正是我在搜索相同错误时所寻找的 (2认同)