我正在尝试在 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,则这必须是一个普通对象,其形状与传递给它的键的形状相同。否则,您可以自由传递您的减速器可以理解的任何内容。
我有什么遗漏吗?我现在只是记录状态。它现在没有发生。我在这里参考了这些视频来学习 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;
博客列表减速器:
function blogList (state, action) {
console.log(action,state);
return state;
}
module.export = blogList;
PS:我正在使用 React Router 和 redux。我可以从反应开发工具中看到 store.getState 中的路由。