My hot reload in Create React app broke due to updating some packages (probably because of typescript
). I had to solve it without the ejecting of CRA.
I managed to fix it by upgrading to version 16.10 of these packages:
"react": "^16.10.0",
"react-dom": "^16.10.0"
And it worked just fine!
My code in index.tsx
:
...
const isDev = process.env.NODE_ENV === 'development'
const rootEl = document.getElementById('root')
ReactDOM.render(<App />, rootEl)
if (isDev && module.hot) {
module.hot.accept('screens/App', () => {
ReactDOM.render(<App />, rootEl)
})
}
Hint:
First try just this code (maybe you are setting wrong path)
if (module.hot) {
module.hot.accept()
}
If this start working then you want to specify the path in order to make hot loading more effective (less bubbling = shorter loading)
npm start
, or loading it by opening it from the html file. Probably a stupid question, but its worth asking sometimes... – Mute