Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@klzns
Created August 15, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klzns/9be261950e018472d288f5224153979b to your computer and use it in GitHub Desktop.
Save klzns/9be261950e018472d288f5224153979b to your computer and use it in GitHub Desktop.
How to add hot module replacement (react-hot-loader) in Create React App
import { AppContainer } from 'react-hot-loader' // Install `npm install react-hot-loader@next`
import React from 'react'
import App from './App'
const renderApp = (Root) => {
React.render(
<AppContainer>
<Root />
</AppContainer>,
document.getElementById('app-root')
)
}
renderApp(App)
if (module.hot) {
module.hot.accept('./App', () => {
const NewApp = require('./App').default
renderApp(NewApp)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment