2016-07-30 146 views
1

我试图在createStore中传递初始状态,但它在控制台中显示错误/警告。无法通过Redux中的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):初始状态。您可以选择将其指定为通用应用程序中的服务器状态,或恢复先前序列化的用户会话。 如果您使用combineReducers制作减速器,则它必须是与传递给它的键形状相同的普通对象。否则,你可以自由地传递你的reducer可以理解的任何东西。

有什么我失踪?我现在只是记录状态。现在它不会发生。我提到这些视频,了解终极版here.

这里是我的店铺代码:

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减速机:

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

module.export = blogList; 

附: :我正在使用React Router和redux。我可以在反应开发工具中看到store.getState中的路由。

+1

如果您在您的rootReducer文件中调试var blogList是否定义了? –

+0

@ The Brofessor,谢谢你的提示。 blogList是在rootReducer中定义的,但它是空对象(typeof blogList === object)。然而对于rootReducer来说,它是功能。我是以错误的方式输出吗? –

+0

@Br教授,我用根减速器直接调用了它的功能,它工作。我相信错误应该是由于出口。 –

回答

1

我相信它的错字和blogList文件的最后一行应该是module.exports而不是module.export