Open fabriziomoscon opened 8 years ago
In theory that should work, with the exception that we would need to require('./reducer')
inside the accept
callback, and modify the reducer.js
file to return a function that creates the new reducer (as implemented in https://github.com/futurice/pepperoni-app-kit/commit/a6c3540be25df66049064f8f2c5052e5d84f84ea):
if (__DEV__ && module.hot) {
module.hot.accept(() => {
const createReducer = require('./reducer').default;
store.replaceReducer(createReducer());
});
}
However when I tried that now, I could not get it to work. The redux hot loading warning no longer shows, and I can also verify in the debugger that the new reducer function gets loaded, but the new reducer behaviour is not taken into use.
I think this is caused by the redux-loop
store enhancer that effectively clones the store when it's taken into use, and the replaceReducer
has no effect because it's modifying the original store instance, and not the cloned one.
This feature would be nifty, but I don't currently have time to dig deeper into this.
+1
@fabriziomoscon did you find a way to get hot reloading in redux working ?
@tino-junge I haven't managed to make it work.
In my case that snippet generate an infinite loop which reaches Max call stack at some point. This happens every time I make a change to a *State.js
file
It seems by the look of it that the code to make Hot Module Reload with redux is missing.
See examples here: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/create.js#L28-L32
and here: https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html#redux-stores
@jevakallio do you think this code in
store.js
will work?