{"id":13394819,"url":"https://github.com/gaearon/react-hot-loader","last_synced_at":"2025-05-13T15:07:29.168Z","repository":{"id":18576054,"uuid":"21779020","full_name":"gaearon/react-hot-loader","owner":"gaearon","description":"Tweak React components in real time. (Deprecated: use Fast Refresh instead.)","archived":false,"fork":false,"pushed_at":"2023-02-10T02:42:07.000Z","size":9389,"stargazers_count":12242,"open_issues_count":463,"forks_count":798,"subscribers_count":172,"default_branch":"master","last_synced_at":"2025-05-06T14:48:49.475Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://gaearon.github.io/react-hot-loader/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gaearon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-07-12T23:49:43.000Z","updated_at":"2025-05-05T18:13:26.000Z","dependencies_parsed_at":"2024-04-12T01:21:14.470Z","dependency_job_id":"662c5431-6d10-40cd-9959-a368fdf63024","html_url":"https://github.com/gaearon/react-hot-loader","commit_stats":{"total_commits":1543,"total_committers":250,"mean_commits":6.172,"dds":0.6701231367465975,"last_synced_commit":"07d1f4e080f18dd83273be5bd02863ce1caf892e"},"previous_names":[],"tags_count":176,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaearon%2Freact-hot-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaearon%2Freact-hot-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaearon%2Freact-hot-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaearon%2Freact-hot-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gaearon","download_url":"https://codeload.github.com/gaearon/react-hot-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253365461,"owners_count":21897186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:32.676Z","updated_at":"2025-05-13T15:07:29.132Z","avatar_url":"https://github.com/gaearon.png","language":"JavaScript","funding_links":["https://opencollective.com/react-hot-loader"],"categories":["JavaScript","Uncategorized","Loader options","Awesome React","Framework Developer Tools","\u003e 10k ★","目录","Web 前端",":hammer_and_wrench: 开发","Tools","React [🔝](#readme)","Веб-разработка"],"sub_categories":["Uncategorized","forkChecker *(boolean) (default=false)*","Tools","编写代码","JavaScript"],"readme":"# React Hot Loader\n\n[![Build Status][build-badge]][build] [![version][version-badge]][package]\n[![Code Coverage][coverage-badge]][coverage]\n[![MIT License][license-badge]][license]\n\n[![PRs Welcome][prs-badge]][prs] [![Chat][chat-badge]][chat]\n[![Backers on Open Collective][oc-backer-badge]](#backers)\n[![Sponsors on Open Collective][oc-sponsor-badge]](#sponsors)\n\n[![Watch on GitHub][github-watch-badge]][github-watch]\n[![Star on GitHub][github-star-badge]][github-star]\n\nTweak React components in real time ⚛️⚡️\n\nWatch\n**[Dan Abramov's talk on Hot Reloading with Time Travel](https://www.youtube.com/watch?v=xsSnOQynTHs).**\n\n# Moving towards next step\n\nReact-Hot-Loader has been your friendly neighbour, living outside of React. But it has been limiting its powers and causing not the greatest experience. It's time to make a next step.\n\n**React-Hot-Loader is expected to be replaced by [React Fast Refresh](https://github.com/facebook/react/issues/16604)**. Please remove React-Hot-Loader if Fast Refresh is currently supported on your environment.\n\n* `React Native` - [supports Fast Refresh](https://facebook.github.io/react-native/docs/fast-refresh) since 0.61.\n* `parcel 2` - [supports Fast Refresh](https://github.com/facebook/react/issues/16604#issuecomment-556082893) since alpha 3.\n* `webpack` - [supports Fast Refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin/) using a plugin.\n* `other bundler` - no support yet, use React-Hot-Loader\n* `create-react-app` - [supports Fast Refresh](https://create-react-app.dev/docs/advanced-configuration/) with FAST_REFRESH env since 4.\n* `next.js` - [supports Fast Refresh](https://nextjs.org/docs/basic-features/fast-refresh) since 9.4\n\n## Install\n\n```\nnpm install react-hot-loader\n```\n\n\u003e Note: You can safely install react-hot-loader as a regular dependency instead\n\u003e of a dev dependency as it automatically ensures it is not executed in\n\u003e production and the footprint is minimal.\n\n## Getting started\n\n1.  Add `react-hot-loader/babel` to your `.babelrc`:\n\n```js\n// .babelrc\n{\n  \"plugins\": [\"react-hot-loader/babel\"]\n}\n```\n\n2.  Mark your root component as _hot-exported_:\n\n```js\n// App.js\nimport { hot } from 'react-hot-loader/root';\nconst App = () =\u003e \u003cdiv\u003eHello World!\u003c/div\u003e;\nexport default hot(App);\n```\n\n3.  Make sure `react-hot-loader` is required before `react` and `react-dom`:\n\n* or `import 'react-hot-loader'` in your main file (before React)\n* or prepend your webpack entry point with `react-hot-loader/patch`, for example:\n  ```js\n  // webpack.config.js\n  module.exports = {\n    entry: ['react-hot-loader/patch', './src'],\n    // ...\n  };\n  ```\n\n4.  If you need hooks support, use [`@hot-loader/react-dom`](#hot-loaderreact-dom)\n\n### Hook support\n\nHooks would be auto updated on HMR if they _should_ be.\nThere is only one condition for it - a non zero dependencies list.\n\n```js\n❄️ useState(initialState); // will never updated (preserve state)\n❄️ useEffect(effect); // no need to update, updated on every render\n❄️ useEffect(effect, []); // \"on mount\" hook. \"Not changing the past\"\n🔥 useEffect(effect, [anyDep]); // would be updated\n\n🔥 useEffect(effect, [\"hot\"]); // the simplest way to make hook reloadable\n```\n\n**Plus**\n\n* any hook would be reloaded on a function body change. Enabled by default, controlled by `reloadHooksOnBodyChange` option.\n* you may configure RHL to reload any hook by setting `reloadLifeCycleHooks` option to true.\n\n**To disable hooks reloading** - set configuration option:\n\n```js\nimport { setConfig } from 'react-hot-loader';\n\nsetConfig({\n  reloadHooks: false,\n});\n```\n\nWith this option set **all** `useEffects`, `useCallbacks` and `useMemo` would be updated on Hot Module Replacement.\n\n### Hooks reset\n\nHooks would be reset if their order changes. Adding, removing or moving around would\ncause a local tree remount.\n\n**Babel plugin is required** for this operation. Without it changing hook order would throw an error\nwhich would be propagated till the nearest class-based component.\n\n## `@hot-loader/react-dom`\n\n[`@hot-loader/react-dom`](https://github.com/hot-loader/react-dom) replaces the \"react-dom\" package of the same version, but with additional patches to support hot reloading.\n\nThere are 2 ways to install it:\n\n* Use **yarn** name resolution, so `@hot-loader/react-dom` would be installed instead of `react-dom`\n\n```\nyarn add react-dom@npm:@hot-loader/react-dom\n```\n\n* Use [webpack aliases](https://webpack.js.org/configuration/resolve/#resolvealias)\n\n```\nyarn add @hot-loader/react-dom\n```\n\n```js\n// webpack.config.js\nmodule.exports = {\n  // ...\n  resolve: {\n    alias: {\n      'react-dom': '@hot-loader/react-dom',\n    },\n  },\n};\n```\n\n### Old API\n\n**Note:** There is also an old version of `hot`, used prior to version 4.5.4. **Please use the new one**,\nas it is much more resilient to js errors that you may make during development.\n\nMeanwhile, not all the bundlers are compatible with new `/root` API, for example **[parcel](http://parceljs.org/) is not**.\n\nReact-Hot-Load will throw an error, asking you to use the old API, if such incompatibility would be detected.\nIt is almost the same, but you have to pass `module` inside `hot`.\n\n```js\nimport { hot } from 'react-hot-loader';\nconst App = () =\u003e \u003cdiv\u003eHello World!\u003c/div\u003e;\nexport default hot(module)(App);\n```\n\n3.  [Run webpack with Hot Module Replacement](https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr):\n\n```sh\nwebpack-dev-server --hot\n```\n\n## What about production?\n\nThe webpack patch, `hot`, Babel plugin, `@hot-loader/react-dom` etc. are all safe to use in production; they leave a minimal footprint, so there is no need to complicate your configuration based on the environment. Using the Babel plugin in production is even recommended because it switches to cleanup mode.\n\nJust ensure that the production mode has been properly set, both as an environment variable and in your bundler. E.g. with webpack you would build your code by running something like:\n\n```\nNODE_ENV=production webpack --mode production\n```\n\n`NODE_ENV=production` is needed for the Babel plugin, while `--mode production` uses [`webpack.DefinePlugin`](https://webpack.js.org/plugins/define-plugin/) to set `process.env.NODE_ENV` inside the compiled code itself, which is used by `hot` and `@hot-loader/react-dom`.\n\nMake sure to watch your bundle size when implementing react-hot-loader to ensure that you did it correctly.\n\n## Limitations\n\n* (that's the goal) React-Hot-Loader would not change the past, only update the present - no lifecycle event would be called on component update. As a result, any code changes made to `componentWillUnmount` or `componentDidMount` would be ignored for already created components.\n* (that's the goal) React-Hot-Loader would not update any object, including component `state`.\n* (1%) React-Hot-Loader may not apply some changes made to a component's `constructor`. Unless an existing component is recreated, RHL would typically _inject_ new data into that component, but there is no way to detect the actual change or the way it was applied, especially if the change was made to a function. This is because of the way React-Hot-Loader works - it knows what class functions are, not how they were created. See [#1001](https://github.com/gaearon/react-hot-loader/issues/1001) for details.\n\n## Recipes\n\n### Migrating from [create-react-app](https://github.com/facebookincubator/create-react-app)\n\n1.  Run `npm run eject`\n2.  Install React Hot Loader (`npm install --save-dev react-hot-loader`)\n3.  In `config/webpack.config.dev.js`, add `'react-hot-loader/babel'` to Babel\n    loader configuration. The loader should now look like:\n\n```js\n  {\n    test: /\\.(js|jsx)$/,\n    include: paths.appSrc,\n    loader: require.resolve('babel-loader'),\n    options: {\n      // This is a feature of `babel-loader` for webpack (not Babel itself).\n      // It enables caching results in ./node_modules/.cache/babel-loader/\n      // directory for faster rebuilds.\n      cacheDirectory: true,\n      plugins: ['react-hot-loader/babel'],\n    },\n  }\n```\n\n4.  Mark your App (`src/App.js`) as _hot-exported_:\n\n```js\n// ./containers/App.js\nimport React from 'react';\nimport { hot } from 'react-hot-loader';\n\nconst App = () =\u003e \u003cdiv\u003eHello World!\u003c/div\u003e;\n\nexport default hot(module)(App);\n```\n\n### Migrating from [create-react-app](https://github.com/facebookincubator/create-react-app) without ejecting\n\nUsers [report](https://github.com/gaearon/react-hot-loader/pull/729#issuecomment-354097936), that it is possible to use [react-app-rewire-hot-loader](https://github.com/cdharris/react-app-rewire-hot-loader) to setup React-hot-loader without ejecting.\n\n### TypeScript\n\nAs of version 4, React Hot Loader requires you to pass your code through [Babel](http://babeljs.io/) to transform it so that it can be hot-reloaded. This can be a pain point for TypeScript users, who usually do not need to integrate Babel as part of their build process.\n\nFortunately, it's simpler than it may seem! Babel will happily parse TypeScript syntax and can act as an alternative to the TypeScript compiler, so you can safely replace `ts-loader` or `awesome-typescript-loader` in your Webpack configuration with `babel-loader`. Babel won't typecheck your code, but you can use [`fork-ts-checker-webpack-plugin`](https://github.com/Realytics/fork-ts-checker-webpack-plugin) (and/or invoke `tsc --noEmit`) as part of your build process instead.\n\nA sample configuration:\n\n```js\n{\n  // ...you'll probably need to configure the usual Webpack fields like \"mode\" and \"entry\", too.\n  resolve: { extensions: [\".ts\", \".tsx\", \".js\", \".jsx\"] },\n  module: {\n    rules: [\n      {\n        test: /\\.(j|t)sx?$/,\n        exclude: /node_modules/,\n        use: {\n          loader: \"babel-loader\",\n          options: {\n            cacheDirectory: true,\n            babelrc: false,\n            presets: [\n              [\n                \"@babel/preset-env\",\n                { targets: { browsers: \"last 2 versions\" } } // or whatever your project requires\n              ],\n              \"@babel/preset-typescript\",\n              \"@babel/preset-react\"\n            ],\n            plugins: [\n              // plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript\n              [\"@babel/plugin-proposal-decorators\", { legacy: true }],\n              [\"@babel/plugin-proposal-class-properties\", { loose: true }],\n              \"react-hot-loader/babel\"\n            ]\n          }\n        }\n      }\n    ]\n  },\n  plugins: [\n    new ForkTsCheckerWebpackPlugin()\n  ]\n};\n```\n\nFor a full example configuration of TypeScript with React Hot Loader and newest beta version of Babel, check [here](https://github.com/gaearon/react-hot-loader/tree/master/examples/typescript).\n\nAs an alternative to this approach, it's possible to chain Webpack loaders so that your code passes through Babel and then TypeScript (or TypeScript and then Babel), but this approach is not recommended as it is more complex and may be significantly less performant. Read more [discussion here](https://github.com/gaearon/react-hot-loader/issues/884).\n\n### Parcel\n\nParcel supports Hot Module Reloading out of the box, just follow step 1 and 2 of [Getting Started](https://github.com/gaearon/react-hot-loader/tree/master#getting-started).\n\nWe also have a [full example running Parcel + React Hot Loader](https://github.com/gaearon/react-hot-loader/tree/master/examples/parcel).\n\n### Electron\n\nYou need something to mark your modules as hot in order to use React Hot Loader.\n\nOne way of doing this with Electron is to simply use webpack like any web-based project might do and the general guide above describes. See also [this example Electron app](https://github.com/s-h-a-d-o-w/rhl-electron-quick-start).\n\nA webpack-less way of doing it to use `electron-compile` (which is also used by [`electron-forge`](https://electronforge.io)) - see [this example](https://github.com/rllola/hmr-example-issue-2). While it requires less configuration, something to keep in mind is that `electron-compile`'s HMR will always reload all modules, regardless of what was actually edited.\n\n### Source Maps\n\nIf you use `devtool: 'source-map'` (or its equivalent), source maps will be\nemitted to hide hot reloading code.\n\nSource maps slow down your project. Use `devtool: 'eval'` for best build\nperformance.\n\nHot reloading code is just one line in the beginning and one line at the end of\neach module so you might not need source maps at all.\n\n### Linking\n\nIf you are using `npm link` or `yarn link` for development purposes, there is a chance you will get error `Module not found: Error: Cannot resolve module 'react-hot-loader'` or the linked package is not hot reloaded.\n\nThere are 2 ways to fix `Module not found`:\n\n* Use [`include` in loader configuration](https://github.com/gaearon/react-hot-boilerplate/blob/master/webpack.config.js#L22) to only opt-in your app's files to processing.\n* Alternatively if you are using webpack, override the module resolution in your config:\n\n```js\n{\n  resolve: {\n    alias: {\n      'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),\n    }\n  }\n}\n```\n\nAnd to make your linked package to be hot reloaded, it will need to use the patched version of `react` and `react-dom`, if you're using webpack, add this options to the alias config\n\n```js\n{\n  resolve: {\n    alias: {\n      'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),\n      // add these 2 lines below so linked package will reference the patched version of `react` and `react-dom`\n      'react': path.resolve(path.join(__dirname, './node_modules/react')),\n      'react-dom': path.resolve(path.join(__dirname, './node_modules/react-dom')),\n      // or point react-dom above to './node_modules/@hot-loader/react-dom' if you are using it\n    }\n  }\n}\n```\n\n## Preact\n\nReact-hot-loader should work out of the box with `preact-compat`, but, in case of pure preact, you will need\nto configure it:\n\n* create configuration file (setupHotLoader.js)\n\n```js\nimport reactHotLoader from 'react-hot-loader';\nimport preact from 'preact';\n\nreactHotLoader.preact(preact);\n```\n\n* dont forget to import it\n\n#### Preact limitations\n\n* HOCs and Decorators as not supported yet. For Preact React-Hot-Loader v4 behave as v3.\n\n## React Native\n\nReact Native\n**[supports hot reloading natively](https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html)**\nas of version 0.22.\n\nUsing React Hot Loader with React Native can cause unexpected issues (see #824) and is not recommended.\n\n## Webpack plugin\n\nWe recommend using the `babel` plugin, but there are some situations where you are unable to. If so, try the `webpack` plugin / `webpack-loader` (as seen in v3).\n\nRemember - the `webpack` plugin is **not compatible** with class-based components. The `babel` plugin\nwill inject special methods to every class, to make `class members` (like onClick) hot-updatable, while the `webpack` plugin would leave classes as is, without any _instrumentation_.\n\n```js\nclass MyComponent extends React.Component {\n  onClick = () =\u003e this.setState(); // COULD NOT UPDATE\n  variable = 1; // this is ok\n  render() {} // this is ok\n}\n```\n\nBut `webpack-loader` could help with TypeScript or _spreading_ \"cold API\" [to all node_modules](https://github.com/gaearon/react-hot-loader#disabling-a-type-change-for-all-node_modules).\n\n\u003e It is possible to enable this loader for all the files, but if you use `babel` plugin, you need to enable this loader for `react-dom` only. Place it after babel-loader, if babel-loader is present.\n\n```js\n// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      // would only land a \"hot-patch\" to react-dom\n      {\n        test: /\\.js$/,\n        include: /node_modules\\/react-dom/,\n        use: ['react-hot-loader/webpack'],\n      },\n    ],\n  },\n};\n```\n\nWebpack plugin will also land a \"hot\" patch to react-dom, making React-Hot-Loader more compliant to [the principles](https://github.com/gaearon/react-hot-loader/issues/1118).\n\nIf you are not using `babel` plugin you might need to apply `webpack-loader` to all the files.\n\n```js\n{\n  test: /\\.jsx?$/,\n  include: /node_modules/,\n  use: ['react-hot-loader/webpack']\n},\n```\n\n### Code Splitting\n\nIf you want to use Code Splitting + React Hot Loader, the simplest solution is to pick a library compatible with this one:\n\n* [React Lazy](https://reactjs.org/docs/code-splitting.html#reactlazy)\n* [Imported Component](https://github.com/theKashey/react-imported-component)\n* [React Universal Component](https://github.com/faceyspacey/react-universal-component)\n* [React-Loadable](https://github.com/jamiebuilds/react-loadable)\n\nIf you use a not-yet-friendly library, like [react-async-component](https://github.com/ctrlplusb/react-async-component),\nor are having problems with hot reloading failing to reload code-split components,\nyou can manually mark the components below the code-split boundaries.\n\n```js\n// AsyncHello.js\nimport { asyncComponent } from 'react-async-component';\n\n// asyncComponent could not `hot-reload` itself.\nconst AsyncHello = asyncComponent({\n  resolve: () =\u003e import('./Hello'),\n});\n\nexport default AsyncHello;\n```\n\nNote that `Hello` is the component at the root of this particular\ncode-split chunk.\n\n```js\n// Hello.js\nimport { hot } from 'react-hot-loader/root';\n\nconst Hello = () =\u003e 'Hello';\n\nexport default hot(Hello); // \u003c-- module will reload itself\n```\n\nWrapping this root component with `hot()` will ensure that it is hot reloaded correctly.\n\n### Out-of-bound warning\n\nYou may see the following warning when code-split components are updated:\n\n```console\nReact-Hot-Loader: some components were updated out-of-bound. Updating your app to reconcile the changes.\n```\n\nThis is because the hot reloading of code-split components happens asynchronously. If you had an `App.js` that implemented\nthe `AsyncHello` component above and you modified `AsyncHello`, it would be bundled and reloaded at the same time as\n`App.js`. However, the core hot reloading logic is synchronous, meaning that it's possible for the hot reload to run before\nthe updates to the split component have landed.\n\nIn this case, RHL uses a special _tail update detection_ logic, where it notes that an an update to a split component\nhas happened after the core hot reloading logic has already finished, and it triggers another update cycle to ensure\nthat all changes are applied.\n\nThe warning is informational - it is a notice that this tail update logic is triggered, and does not indicate a problem\nin the configuration or useage of `react-hot-loader`.\n\nIf the tail update detection is not something you want or need, you can disable this behavior by setting\n`setConfig({ trackTailUpdates:false })`.\n\n### Checking Element `type`s\n\nBecause React Hot Loader creates proxied versions of your components, comparing\nreference types of elements won't work:\n\n```js\nconst element = \u003cComponent /\u003e;\nconsole.log(element.type === Component); // false\n```\n\nReact Hot Loader exposes a function `areComponentsEqual` to make it possible:\n\n```js\nimport { areComponentsEqual } from 'react-hot-loader';\nconst element = \u003cComponent /\u003e;\nareComponentsEqual(element.type, Component); // true\n```\n\nAnother way - compare \"rendered\" element type\n\n```js\nconst element = \u003cComponent /\u003e;\nconsole.log(element.type === \u003cComponent /\u003e.type); // true\n\n// better - precache rendered type\nconst element = \u003cComponent /\u003e;\nconst ComponentType = \u003cComponent /\u003e.type;\nconsole.log(element.type === ComponentType); // true\n```\n\nBut you might have to provide all required props. See [original issue](https://github.com/gaearon/react-hot-loader/issues/304).\nThis is most reliable way to compare components, but it will not work with required props.\n\nAnother way - compare Component name.\n\n\u003e Not all components have a name. **In production displayName could not exists.**\n\n```js\nconst element = \u003cComponent /\u003e;\nconsole.log(element.displayName === 'Component'); // true\n```\n\nThis is something we did not solve yet. Cold API could help keep original types.\n\n### Webpack ExtractTextPlugin\n\nwebpack ExtractTextPlugin is not compatible with React Hot Loader. Please disable it in development:\n\n```js\nnew ExtractTextPlugin({\n  filename: 'styles/[name].[contenthash].css',\n  disable: NODE_ENV !== 'production',\n});\n```\n\n#### Disabling a type change (❄️)\n\nIt is possible to disable React-Hot-Loader for a specific component, especially to\nenable common way to type comparison.\nSee #991 for the idea behind ⛄️, and #304 about \"type comparison\" problem.\n\n```js\nimport { cold } from 'react-hot-loader';\n\ncold(SomeComponent) // this component will ignored by React-Hot-Loader\n\u003cSomeComponent /\u003e.type === SomeComponent // true\n```\n\nIf you will update `cold` component React-Hot-Loader will complain (on error level), and then\nReact will cold-replace Component with a internal state lose.\n\n\u003e Reach-Hot-Loader: cold element got updated\n\n##### Disabling a type change for all node_modules\n\nYou may _cold_ all components from node_modules. This will not work for HOC(like Redux) or dynamically created Components, but might help in most of situations, when type changes\nare not welcomed, and modules are not expected to change.\n\n```js\nimport { setConfig, cold } from 'react-hot-loader';\nsetConfig({\n  onComponentRegister: (type, name, file) =\u003e file.indexOf('node_modules') \u003e 0 \u0026\u0026 cold(type),\n\n  // some components are not visible as top level variables,\n  // thus its not known where they were created\n  onComponentCreate: (type, name) =\u003e name.indexOf('styled') \u003e 0 \u0026\u0026 cold(type),\n});\n```\n\n! To be able to \"cold\" components from 'node_modules' you have to apply babel to node_modules, while this\nfolder is usually excluded.\nYou may add one more babel-loader, with only one React-Hot-Loader plugin inside to solve this.\n**Consider using webpack-loader** for this.\n\n##### React-Hooks\n\nReact hooks are not _really_ supported by React-Hot-Loader. Mostly due to our internal\nprocesses of re-rendering React Tree, which is required to reconcile an updated application\nbefore React will try to rerender it, and fail to do that, obviously.\n\n* hooks **should work** for versions 4.6.0 and above (`pureSFC` is enabled by default).\n* hooks will produce **errors** on every hot-update without patches to `react-dom`.\n* hooks **may loss the state** without patches to `react-dom`.\n* hooks does not support adding new hooks on the fly\n* change in hooks for a mounted components will cause a runtime exception, and a `retry` button (at the nearest class component) will be shown.\n  Pressing a `retry` button will basically remount tree branch.\n\nTo mitigate any hook-related issues (and disable their hot-reloadability) - `cold` them.\n\n* _cold_ components using hooks.\n\n```js\nimport { setConfig, cold } from 'react-hot-loader';\nsetConfig({\n  onComponentCreate: (type, name) =\u003e\n    (String(type).indexOf('useState') \u003e 0 || String(type).indexOf('useEffect') \u003e 0) \u0026\u0026 cold(type),\n});\n```\n\n## API\n\n### `hot(Component, options)`\n\nMark a component as hot.\n\n#### Babel plugin\n\nRight now babel plugin has only one option, enabled by default.\n\n* `safetyNet` - will help you properly setup ReactHotLoader.\n\nYou may disable it to get more control on the module execution order.\n\n```js\n//.babelrc\n{\n    \"plugins\": [\n        [\n            \"react-hot-loader/babel\",\n            {\n            \"safetyNet\": false\n            }\n        ]\n    ]\n}\n```\n\n#### Important\n\n**!!** Use `hot` only for module `exports`, not for module `imports`. **!!**\n\n```js\nimport { hot } from 'react-hot-loader/root';\n\nconst App = () =\u003e 'Hello World!';\n\nexport default hot(App);\n```\n\nKeep in mind - by importing `react-hot-loader/root` you are setting up a boundary for update event propagation.\n\nThe higher(in module hierarchy) you have it - the more stuff would be updated on Hot Module Replacement.\n\nTo make RHL more reliable and safe, please place `hot` _below_ (ie somewhere in _imported_ modules):\n\n* react-dom\n* redux store creation\n* any data, you want to preserve between updates\n* big libraries\n\nYou may(but it's not required) place `hot` to the every route/page/feature/lazy chunk, thus make updates more scoped.\n\nYou don't need to wrap every component with `hot`, application works fine with a single one.\n\n### (old)`hot(module, options)(Component, options)`\n\nMark a component as hot. The \"new\" hot is just hidding the first part - `hot(module)`, giving you\nonly the second `(App)`. The \"new\" hot is using old API.\n\n```js\nimport { hot } from 'react-hot-loader';\n\nconst App = () =\u003e 'Hello World!';\n\nexport default hot(module)(App);\n```\n\n### `AppContainer`\n\nMark application as hot reloadable. (**Prefer** using `hot` helper, see below for migration details).\n\nThis low-level approach lets you make **hot **imports\\_\\_, not exports.\n\n```js\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport { AppContainer } from 'react-hot-loader';\nimport App from './containers/App';\n\nconst render = Component =\u003e {\n  ReactDOM.render(\n    \u003cAppContainer\u003e\n      \u003cComponent /\u003e\n    \u003c/AppContainer\u003e,\n    document.getElementById('root'),\n  );\n};\n\nrender(App);\n\n// webpack Hot Module Replacement API\nif (module.hot) {\n  // keep in mind - here you are configuring HMR to accept CHILDREN MODULE\n  // while `hot` would configure HMR for the CURRENT module\n  module.hot.accept('./containers/App', () =\u003e {\n    // if you are using harmony modules ({modules:false})\n    render(App);\n    // in all other cases - re-require App manually\n    render(require('./containers/App'));\n  });\n}\n```\n\n### areComponentsEqual(Component1, Component2)\n\nTest if two components have the same type.\n\n```js\nimport { areComponentsEqual } from 'react-hot-loader';\nimport Component1 from './Component1';\nimport Component2 from './Component2';\n\nareComponentsEqual(Component1, Component2); // true or false\n```\n\n### setConfig(config)\n\nSet a new configuration for React Hot Loader.\n\nAvailable options are:\n\n* `logLevel`: specify log level, default to `\"error\"`, available values are: `['debug', 'log', 'warn', 'error']`\n* `pureSFC`: enable Stateless Functional Component. If disabled they will be converted to React Components.\n  Default value: false.\n* `ignoreSFC`: skip \"patch\" for SFC. \"Hot loading\" could still work, with webpack-patch present\n* `pureRender`: do not amend `render` method of any component.\n* for the rest see [index.d.ts](https://github.com/gaearon/react-hot-loader/blob/master/index.d.ts#L62-L133).\n\n```js\n// rhlConfig.js\nimport { setConfig } from 'react-hot-loader';\n\nsetConfig({ logLevel: 'debug' });\n```\n\n**It is important** to set configuration before any other action will take a place\n\n```js\n// index.js\nimport './rhlConfig' // \u003c-- extract configuration to a separate file, and import it in the beggining\nimport React from 'react'\n....\n```\n\n## Migrating from v3\n\n### AppContainer vs hot\n\nPrior v4 the right way to setup React Hot Loader was to wrap your Application\nwith `AppContainer`, set setup module acceptance by yourself. This approach is\nstill valid but only for advanced use cases, prefer using `hot` helper.\n\n**React Hot Loader v3:**\n\n```js\n// App.js\nimport React from 'react';\n\nconst App = () =\u003e \u003cdiv\u003eHello world!\u003c/div\u003e;\n\nexport default App;\n```\n\n```js\n// main.js\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport { AppContainer } from 'react-hot-loader';\nimport App from './containers/App';\n\nconst render = Component =\u003e {\n  ReactDOM.render(\n    \u003cAppContainer\u003e\n      \u003cComponent /\u003e\n    \u003c/AppContainer\u003e,\n    document.getElementById('root'),\n  );\n};\n\nrender(App);\n\n// webpack Hot Module Replacement API\nif (module.hot) {\n  module.hot.accept('./containers/App', () =\u003e {\n    // if you are using harmony modules ({modules:false})\n    render(App);\n    // in all other cases - re-require App manually\n    render(require('./containers/App'));\n  });\n}\n```\n\n**React Hot Loader v4:**\n\n```js\n// App.js\nimport React from 'react';\nimport { hot } from 'react-hot-loader';\n\nconst App = () =\u003e \u003cdiv\u003eHello world!\u003c/div\u003e;\n\nexport default hot(module)(App);\n```\n\n```js\n// main.js\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './containers/App';\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById('root'));\n```\n\n### Patch is optional\n\n\u003e Since 4.0 till 4.8\n\nCode is automatically patched, you can safely remove `react-hot-loader/patch` from your webpack config,\nif react-hot-loader is required before React in any other way.\n\n### Error Boundary is inside every component\n\n\u003e Since 4.5.4\n\nOn Hot Module Update we will inject `componentDidCatch` and a _special_ `render`\nto every Class-based component you have, making [Error Boundaries](https://reactjs.org/docs/error-boundaries.html#introducing-error-boundaries) more local.\n\nAfter update we will remove all sugar, keeping only Boundaries you've created.\n\nYou can provide your own `errorReporter`, via `setConfig({errorReporter})` or opt-out from\nroot ErrorBoundaries setting `errorBoundary={false}` prop on `AppContainer` or `hot`.\nHowever - this option affects only SFC behavior, and any ClassComponent would boundary itself.\n\n```js\nimport { setConfig } from 'react-hot-loader';\nimport ErrorBoundary from './ErrorBoundary';\n\n// ErrorBoundary will be given error and errorInfo prop.\nsetConfig({ errorReporter: ErrorBoundary });\n```\n\nIf `errorReporter` is not set - full screen error overlay would be shown.\n\n#### Setting global Error Reporter\n\nGlobal Error Reporter would, created a fixed overlay on top the page,\nwould be used to display errors, not handled by `errorReporter`, and\nany HMR error.\n\nYou may change, or disable this global error overlay\n\n```js\n// to disable\nsetConfig({ ErrorOverlay: () =\u003e null });\n\n// to change\nsetConfig({ ErrorOverlay: MyErrorOverlay });\n```\n\nThe UX of existing overlay is a subject to change, and we are open to any proposals.\n\n## Known limitations and side effects\n\n### Note about `hot`\n\n`hot` accepts only React Component (Stateful or Stateless), resulting the `HotExported` variant of it.\nThe `hot` function will setup current module to _self-accept_ itself on reload, and will **ignore** all the changes, made for non-React components.\nYou may mark as many modules as you want. But `HotExportedComponent` **should be the only used export** of a _hot_-module.\n\n\u003e Note: Please note how often we have used `exported` keyword. `hot` is for exports.\n\n\u003e Note: Does nothing in production mode, just passes App through.\n\n### New Components keep executing the old code\n\nThere is no way to hot-update constructor code, as result even new components\nwill be born as the first ones, and then grow into the last ones. As of today, this issue cannot be solved.\n\n## Troubleshooting\n\nIf it doesn't work, in 99% of cases it's a configuration issue. A missing option, a\nwrong path or port. webpack is very strict about configuration, and the best way\nto find out what's wrong is to compare your project to an already working setup,\ncheck out\n**[examples](https://github.com/gaearon/react-hot-loader/tree/master/examples)**,\nbit by bit.\n\nIf something doesn't work, in 99% of cases it's an issue with your code. The Component\ndidn't get registered, due to HOC or Decorator around it, which is making it\ninvisible to the Babel plugin or webpack loader.\n\nWe're also gathering\n**[Troubleshooting Recipes](https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md)**\nso send a PR if you have a lesson to share!\n\n### Switch into debug mode\n\nDebug mode adds additional warnings and can tells you why React Hot Loader is\nnot working properly in your application.\n\n```js\nimport { setConfig } from 'react-hot-loader';\nsetConfig({ logLevel: 'debug' });\n```\n\n## Contributors\n\nThis project exists thanks to all the people who contribute. [Contribute](CONTRIBUTING.md).\n[![contributors][oc-contributors-img]](https://github.com/gaearon/react-hot-loader/graphs/contributors)\n\n## Backers\n\nThank you to all our backers! 🙏 [Become a backer][oc-backer-link]\n[![backers][oc-backer-img]][oc-backer-link]\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor][oc-sponsor-link]\n\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/0/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/1/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/2/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/3/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/3/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/4/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/5/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/6/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/7/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/7/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/8/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/react-hot-loader/sponsor/9/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/react-hot-loader/sponsor/9/avatar.svg\"\u003e\u003c/a\u003e\n\n## License\n\nMIT\n\n[build-badge]: https://img.shields.io/travis/gaearon/react-hot-loader.svg?style=flat-square\n[build]: https://travis-ci.org/gaearon/react-hot-loader\n[coverage-badge]: https://img.shields.io/codecov/c/github/gaearon/react-hot-loader.svg?style=flat-square\n[coverage]: https://codecov.io/github/gaearon/react-hot-loader\n[version-badge]: https://img.shields.io/npm/v/react-hot-loader.svg?style=flat-square\n[package]: https://www.npmjs.com/package/react-hot-loader\n[license-badge]: https://img.shields.io/npm/l/react-hot-loader.svg?style=flat-square\n[license]: https://github.com/gaearon/react-hot-loader/blob/next/LICENSE\n[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\n[prs]: http://makeapullrequest.com\n[chat]: https://gitter.im/gaearon/react-hot-loader\n[chat-badge]: https://img.shields.io/gitter/room/gaearon/react-hot-loader.svg?style=flat-square\n[github-watch-badge]: https://img.shields.io/github/watchers/gaearon/react-hot-loader.svg?style=social\n[github-watch]: https://github.com/gaearon/react-hot-loader/watchers\n[github-star-badge]: https://img.shields.io/github/stars/gaearon/react-hot-loader.svg?style=social\n[github-star]: https://github.com/gaearon/react-hot-loader/stargazers\n[oc-backer-badge]: https://opencollective.com/react-hot-loader/backers/badge.svg\n[oc-sponsor-badge]: https://opencollective.com/react-hot-loader/sponsors/badge.svg\n[oc-contributors-img]: https://opencollective.com/react-hot-loader/contributors.svg?width=890\u0026button=false\n[oc-backer-img]: https://opencollective.com/react-hot-loader/backers.svg?width=890\n[oc-backer-link]: https://opencollective.com/react-hot-loader#backers\n[oc-sponsor-link]: https://opencollective.com/react-hot-loader#sponsor\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaearon%2Freact-hot-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaearon%2Freact-hot-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaearon%2Freact-hot-loader/lists"}