Skip to content

Instantly share code, notes, and snippets.

@iamso1
Last active May 3, 2016 15:34
Show Gist options
  • Save iamso1/8911844c6c3d5b34e99fcb735477f028 to your computer and use it in GitHub Desktop.
Save iamso1/8911844c6c3d5b34e99fcb735477f028 to your computer and use it in GitHub Desktop.
解決 Actions must be plain objects. Use custom middleware for async actions 的問題
import { createStore, applyMiddleware} from 'redux';
import reducers from '../reducers';
import thunk from 'redux-thunk';
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
export default function(initialState){
const store = createStoreWithMiddleware(reducers, initialState);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextRootReducer = require('../reducers');
store.replaceReducer(nextRootReducer);
});
}
return store;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment