question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document React Hot Loader 3

See original GitHub issue

It features two modes (react-hot-loader/babel and react-hot-loader/webpack), doesn’t hide HMR API (you have to add module.hot.accept call yourself) and has a somewhat different API and setup process.

There’s info in https://github.com/gaearon/react-hot-boilerplate/pull/61 and https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915 but we should create good step-by-step docs and update the website too.

This will take a while because it’s not a priority for me. If you want to contribute, you are very welcome! Obviously we can’t release 3.0 without any docs.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:18
  • Comments:32 (6 by maintainers)

github_iconTop GitHub Comments

49reactions
gaearoncommented, Apr 19, 2016

We need to update this intro.

The new intro would be slightly longer because there is a bit more setup involved. I would split it into several sections:

  1. Enabling HMR
    • Create a development Webpack config separate from production one
    • Add HotModuleReplacementPlugin to development Webpack config
    • If you only render on the client, consider using WebpackDevServer
      • Easier to set up
      • Enable hot: true and add its entry points
    • If you use server rendering, consider using Express server + webpack-dev-middleware
      • More work but also more control
      • Show how to add webpack-dev-middleware and its entry point
  2. Using HMR to replace the root component
    • Show how to add module.hot hook to re-render your root component
    • (This will not preserve state but is good enough for some cases!)
  3. Adding React Hot Loader to preserve state
    • If you use Babel:
      • Add react-hot-loader/babel to plugins
    • If you don’t use Babel:
      • Add react-hot-loader/webpack to loaders
    • Add react-hot-loader/patch as the first entry point
    • Change your index.js to render <AppContainer> instead of your root component
    • That’s it!
6reactions
janeklbcommented, Sep 4, 2016

@wmertens I agree, its a bit wet so I’ve been doing something like:

// ... all other stuff
import RootElement from './RootElement';

renderWithHotReload(RootElement);

// Hot Module Replacement API
if (module.hot) {
  module.hot.accept('./RootElement', () => {
    const RootElement = require('./RootElement').default;
    renderWithHotReload(RootElement);
  });
}

function renderWithHotReload(RootElement) {
  render(
    <AppContainer>
      <Provider store={store}>
        <RootElement />
      </Provider>
    </AppContainer>,
    document.getElementById('quickpick-root')
  );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub - gaearon/react-hot-loader
React -Hot-Loader has been your friendly neighbour, living outside of React. But it has been limiting its powers and causing not the greatest...
Read more >
Getting Started · React Hot Loader - Dan gaearon
React Hot Loader is a plugin that allows React components to be live reloaded without the loss of state. It works with Webpack...
Read more >
react-hot-loader - npm
react -hot-loader. TypeScript icon, indicating that this package has built-in type declarations. 3.1.3 • Public • Published 5 years ago.
Read more >
Set up React Hot Loader in 10 minutes - LogRocket Blog
A hot reload to an app will only refresh the files that were changed without losing the application's state. · A live reload...
Read more >
Top 5 react-hot-loader Code Examples - Snyk
To help you get started, we've selected a few react-hot-loader examples, based on popular ways it is used in public projects. ; const...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found