2016-07-30 44 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

相關問題