Created
August 15, 2017 17:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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