Skip to content

Instantly share code, notes, and snippets.

@gaearon

gaearon/naive.js Secret

Last active May 9, 2017 10:43
Show Gist options
  • Save gaearon/06bd9e2223556cb0d841 to your computer and use it in GitHub Desktop.
Save gaearon/06bd9e2223556cb0d841 to your computer and use it in GitHub Desktop.
var App = require('./App')
var React = require('react')
var ReactDOM = require('react-dom')
// Render the root component normally
var rootEl = document.getElementById('root')
ReactDOM.render(<App />, rootEl)
// Are we in development mode?
if (module.hot) {
// Whenever a new version of App.js is available
module.hot.accept('./App', function () {
// Require the new version and render it instead
var NextApp = require('./App')
ReactDOM.render(<NextApp />, rootEl)
})
}
@linus-amg
Copy link

that was the best starting point on finding out how to implement hmr for something else then react, thank you very much!

@steida
Copy link

steida commented Aug 31, 2016

This is the right receipt for hot reloadable pure apps, aka apps with stateless components and the app state stored elsewhere.
Super nice.

@steida
Copy link

steida commented Sep 8, 2016

React Native version would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment