Hello,
I have detected a problem. The state is lost on Hot Reloading with Create-React-App. For instance:
Step 1:
git clone https://github.com/reactjs/redux.git
cd redux/examples/todo
npm install
npm start
Step 2:
Step 3:
The state will be loss.
For more information: https://github.com/aaronplanell/todolist-react-redux-wcra/issues/1
This is not a problem, it鈥檚 intentional.
Create React App doesn鈥檛 currently support hot reloading for components.
:fearful: But Redux was created for hot reloading and time travelling (as you know, because you are the creator :smile: ). It's very useful (and a great idea!) because sometimes you need to have information in the state for manipulating the UI. Any solution? I love hot reloading and I love too create-react-app :disappointed:
But Redux was created for hot reloading and time travelling (as you know, because you are the creator)
Right, but then it got crazy popular, and hot reloading was still somewhat flaky, and people blamed React and Redux for their broken complicated project configurations 馃槈 . I鈥檇 rather not ship an experimental feature here if people get an impression that it鈥檚 stable and then become disappointed.
Any solution?
Sure, you can use module.hot.accept like described here. This won鈥檛 preserve local state of React components or DOM, but will preserve Redux state.
Thanks a lot @gaearon !!! I will check it tomorrow and I will update my project.
And thanks too to @sheepsteak for his article :+1:
@aaronplanell, there is a great video by ReactCasts that shows how to get HMR working. It shows the same method to get Redux state preserved (as shown in the above linked article), and also how to set it up in a way that _will_ preserve component state and DOM. (Note however, that the latter requires Webpack changes, so an ejection from create-react-app is unfortunately required.)
@indiesquidge , @aaronplanell : yeah, you actually use HMR _without_ ejecting from CRA, you just need to use the "plain" HMR API rather than using React-Hot-Loader. I've got an example of that in my blog post at http://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/ , and I have a bunch of other articles on HMR listed at https://github.com/markerikson/react-redux-links/blob/master/webpack-advanced-techniques.md#hot-module-replacement that might help explain what's going on.
Thanks a lot both of you, @indiesquidge & @markerikson!!!
I fixed it in september with a few lines:
if (module.hot && process.env.NODE_ENV==="development") {
module.hot.accept();
const NextApp = require('./components/App').default;
ReactDOM.render(
<Provider store={store}>
<LocaleProvider locale={caES}>
<NextApp loadMetadata={false}/>
</LocaleProvider>
</Provider>,
document.getElementById('root')
);
}
Nevertheless, I will check all your links in my next Hackaton, hehehe.
Best regards from Barcelona!
PS: _LocaleProvider_ is library of _Ant Design_ and must be removed if you don't use it.
Most helpful comment
Right, but then it got crazy popular, and hot reloading was still somewhat flaky, and people blamed React and Redux for their broken complicated project configurations 馃槈 . I鈥檇 rather not ship an experimental feature here if people get an impression that it鈥檚 stable and then become disappointed.
Sure, you can use
module.hot.acceptlike described here. This won鈥檛 preserve local state of React components or DOM, but will preserve Redux state.