【发布时间】:2018-01-09 17:59:55
【问题描述】:
尝试在我的 react/redux 套件中运行测试后,我收到以下错误。我已经确保我使用redux-immutable 作为文档在回购中的建议,但无济于事。
The initialState argument passed to createStore is of unexpected type. Expected argument to be an instance of Immutable.Collection or Immutable.Record with the following properties:
我正在使用Immutable.JS()
减速器文件:
import { combineReducers } from 'redux-immutable';
import dashboard from '../Dashboard';
import budget from '../Budget';
import { reducer as formReducer } from 'redux-form/immutable';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
const rootReducer = combineReducers({
form: formReducer,
dashboard,
budget
});
export default rootReducer;
存储文件
import {createStore, applyMiddleware, compose} from 'redux';
import thunk from 'redux-thunk';
import reducers from './reducers';
export function configureStore(){
// Use redux dev tools if available, otherwise use default composition;
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducers, {}, composeEnhancers(
applyMiddleware(thunk)
));
return store;
}
尝试
我在store 文件中尝试了以下操作,因为我不知道错误是什么,但它仍然没有工作。
const store = createStore(reducers, Immutable.collection({form: "", dashboard: "", budget: ""}), composeEnhancers(
applyMiddleware(thunk)
));
我还尝试了以下方法:
https://github.com/gajus/redux-immutable
const store = createStore(reducers, Immutable.Map(), composeEnhancers(
applyMiddleware(thunk)
));
我尝试制作一个 Record 不可变对象
const StateRecord = Immutable.Record({
"form": "form",
"dashboard": "dashboard",
"budget": "budget"
});
const store = createStore(reducers, StateRecord, composeEnhancers(
applyMiddleware(thunk)
));
【问题讨论】:
-
initialState 未在您提供的代码中的任何位置定义。为什么不尝试使用空对象?
createStore(reducers, {}, ...) -
@nbkhope 我忘了我之前添加了这个,看看我是否能找到解决办法。对于空对象,我仍然会遇到同样的错误。
-
@nbkhope 添加了一些我尝试过的新东西,但仍然没有
标签: reactjs redux react-redux immutable.js