无法通过Redux

时间:2016-07-30 16:23:56

标签: reactjs redux react-redux react-router-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,则它必须是一个普通对象,其形状与传递给它的键相同。否则,您可以自由地传递减速器可以理解的任何内容。

我有什么遗失的吗?我现在只是记录状态。它现在没有发生。我已将这些视频介绍给了redux 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 };

Root reducer:

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;

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

1 个答案:

答案 0 :(得分:1)

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