React Hot Loader is a utility that enables Hot Module Replacement (HMR) for React components, allowing developers to tweak components in real time without losing application state during development. The current stable version is 4.13.1, which receives frequent bug fixes and minor updates, as evidenced by its release history. It works by patching React's reconciliation process to allow components to be swapped out without re-mounting, preserving component state and improving development efficiency. While it has been a cornerstone for many React development workflows, it is explicitly positioned as being superseded by React Fast Refresh. Users are strongly encouraged to migrate to Fast Refresh if their environment (e.g., React Native, Parcel 2, Webpack with a plugin, Create React App v4+, Next.js v9.4+) supports it, as Fast Refresh offers a more integrated and robust solution. However, React Hot Loader remains a viable option for environments that do not yet support Fast Refresh.
npm install react-hot-loaderVerified import paths — ran on the pinned version, not inferred.
Sets up React Hot Loader with Babel and Webpack, demonstrates basic HMR for a root React component and showcases a reloadable React Hook.
Consult your project's build tool documentation for enabling React Fast Refresh. For Webpack, install `react-refresh-webpack-plugin` and configure it in your Webpack and Babel setups. Remove `react-hot-loader` and its associated Babel plugin/Webpack entry points.
Update your import statements to `import { hot } from 'react-hot-loader/root';` when wrapping your application's root component.Add `resolve: { alias: { 'react-dom': '@hot-loader/react-dom' } }` to your webpack config. Ensure your hooks have non-empty dependency arrays if you expect them to update, or explicitly configure RHL for broader hook reloading.Ensure `react-hot-loader/babel` is included in your `.babelrc` or Babel configuration.
Prepend your webpack entry point with `'react-hot-loader/patch'` (e.g., `entry: ['react-hot-loader/patch', './src']`) or ensure `import 'react-hot-loader';` is the very first statement in your application's main entry file.
Verify that `react-hot-loader/babel` is correctly configured in your Babel setup and that `react-hot-loader/patch` or `import 'react-hot-loader';` is loaded as the absolute first entry point in your application.
Ensure that the component you are exporting (and wrapping with `hot()`) is indeed a React component. Check for typos in exports or ensure the component is fully defined before being exported and hot-wrapped.
Confirm that `'react-hot-loader/patch'` is the very first entry in your Webpack configuration's `entry` array, or that `import 'react-hot-loader';` is the first line of code in your root application file. Also ensure that Webpack's HMR is enabled.