无法通过Redux中的createStore传递初始状态



我试图在createStore中传递初始状态,但它在控制台中显示错误/警告。

Unexpected key "blogList" found in initialState argument passed to createStore. Expected to find one of the known reducer keys instead: "routing". Unexpected keys will be ignored.

伴随着这个错误,我没有得到存储状态下的初始数据。来自文档:

[initialState](any):初始状态。您可以选择将其指定为在通用应用程序中从服务器水合状态,或恢复以前序列化的用户会话如果您使用combineRoducers生成了reducer,则该reducer必须是一个与传递给它的键形状相同的普通对象。否则,您可以自由传递reducer所能理解的任何内容

我缺了什么吗?我现在只是登录状态。现在还没有发生。我在这里参考了这些视频来学习redux。

这是我的商店代码:

var Redux = require('redux');
var syncHistoryWithStore = require('react-router-redux').syncHistoryWithStore;
var browserHistory = require('react-router').browserHistory;
var rootReducer = require('../reducers/index');
//var BlogActions = require('./actions/actions.js');
var blogList = {
  "id":1,
  "heading": "Heading of blogpost : No topic suggested",
  "cardText": "Content of this blogpost is temporary and will be gathered from Server later. Also Reflux is yet to be implemented",
  "date": "16 July, 2016",
  "tags": ["general","react","firstpost"],
  "content": "sample text"
};
var defaultState = {
  blogList: blogList
};
var BlogStore = Redux.createStore( rootReducer, defaultState);
var history = syncHistoryWithStore( browserHistory, BlogStore);
module.exports =  { "store" : BlogStore, "history" : history };

根部减压器:

var combineReducers = require('redux').combineReducers;
var routerReducer = require('react-router-redux').routerReducer;
var blogList = require('./blogList');
var rootReducer = combineReducers({blogList:blogList,routing:routerReducer});
module.exports = rootReducer;

BlogList Reducer:

function blogList (state, action) {
console.log(action,state);
return state;
}
module.export =  blogList;

附言:我正在使用React Router和redux。我可以从react-dev工具中看到store.getState中的路由。

我认为这是一个拼写错误,blogList文件的最后一行应该是module.exports而不是module.export

相关内容

  • 没有找到相关文章

最新更新