Reputation: 285
I am trying to pass initial state in createStore but, it is showing me error/warning in console.
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.
Along with this error i am not getting initial data in store state.
From the docs :
[initialState] (any): The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced reducer with combineReducers, this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your reducer can understand.
Is there anything i am missing ? i am just logging state for now. and its not happening right now. I have referred these videos to learn redux here.
Here is my store code :
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. : I am using React Router along with redux. and i can see routing in store.getState from react dev tools.
Upvotes: 1
Views: 1310
Reputation: 2391
I believe its a typo and the last line of the blogList file should be module.exports
rather than module.export
.
Upvotes: 1