-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Question: Enabling HRM Hot Module Replacement for React? #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@edelgado I guess because |
@gauravtiwari Yeah that's what I'm trying to find out. There doesn't seem to be a single main root DOM element where all react components are rendered into. As far as |
@edelgado Yepp, that's all you need for webpacker side. Don't think you need to For |
Okie, not sure how to do that, but will look into it. Thanks @gauravtiwari for the tips. I'll close this issue as it doesn't seem to be something to do with webpacker. |
I guess it's like this: https://github.com/reactjs/react-rails/blob/master/react_ujs/dist/react_ujs.js#L236 // Something like this - try to get a static class and see if it works
const node = document.querySelector('[data-react-class="SomeClass"]')
if (module.hot) {
module.hot.accept('./containers/rootContainer.js', () => {
const NextRootContainer = require('./containers/rootContainer.js').default;
render(<NextRootContainer />, node);
})
}
// Or to get all nodes
const nodes = document.querySelectorAll('[data-react-class="SomeClass"]')
nodes.forEach(node => console.log(node)) But I am not sure how that all works with webpacker: https://github.com/reactjs/react-rails#use-with-webpacker |
Hi folks, the webpack-dev-server.md doc in this repo mentions that, in order to enable HMR for React we need add
react-hot-loader
as per these instructions.Step one, enabling HMR was easy by adding the
--hot
option to the call forbin/webpack-dev-server
in my Procfile. Additionally, I enabled thehmr
setting in mywebpacker.yml
file.Step 2 says to modify your root container to accept HMR:
Is that something that I need to handle outside of webpacker? I use
react-rails
and thereact_component
Rails view helper to integrate React components into Rails views.I'm suspecting that HMR is not successful in my project because the React code is not setup to accept the hot modules. I get this every time:
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: