UNPKG

30 kBMarkdownView Raw
1# React Hot Loader
2
3[![Build Status][build-badge]][build] [![version][version-badge]][package]
4[![Code Coverage][coverage-badge]][coverage]
5[![MIT License][license-badge]][license]
6
7[![PRs Welcome][prs-badge]][prs] [![Chat][chat-badge]][chat]
8[![Backers on Open Collective][oc-backer-badge]](#backers)
9[![Sponsors on Open Collective][oc-sponsor-badge]](#sponsors)
10
11[![Watch on GitHub][github-watch-badge]][github-watch]
12[![Star on GitHub][github-star-badge]][github-star]
13
14Tweak React components in real time ⚛️⚡️
15
16Watch
17**[Dan Abramov's talk on Hot Reloading with Time Travel](https://www.youtube.com/watch?v=xsSnOQynTHs).**
18
19## Install
20
21```
22npm install react-hot-loader
23```
24
25> Note: You can safely install react-hot-loader as a regular dependency instead
26> of a dev dependency as it automatically ensures it is not executed in
27> production and the footprint is minimal.
28
29## Getting started
30
311. Add `react-hot-loader/babel` to your `.babelrc`:
32
33```js
34// .babelrc
35{
36 "plugins": ["react-hot-loader/babel"]
37}
38```
39
402. Mark your root component as _hot-exported_:
41
42```js
43// App.js
44import { hot } from 'react-hot-loader/root';
45const App = () => <div>Hello World!</div>;
46export default hot(App);
47```
48
493. Make sure `react-hot-loader` is required before `react` and `react-dom`:
50
51* or `import 'react-hot-loader'` in your main file (before React)
52* or prepend your webpack entry point with `react-hot-loader/patch`
53
544. If you need hooks support, use React-🔥-Dom
55
56## React-🔥-Dom
57
58React-🔥-Dom ([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.
59
60There are 2 ways to install it:
61
62* Use **yarn** name resolution, so `@hot-loader/react-dom` would be installed instead of `react-dom`
63
64```
65yarn add react-dom@npm:@hot-loader/react-dom
66```
67
68* Use webpack **aliases**
69
70```
71yarn add @hot-loader/react-dom
72```
73
74```js
75// webpack.conf
76...
77resolve: {
78 alias: {
79 'react-dom': '@hot-loader/react-dom'
80 }
81}
82...
83```
84
85### Old API
86
87**Note:** There is also an old version of `hot`, used prior to version 4.5.4. **Please use the new one**,
88as it is much more resilient to js errors that you may make during development.
89
90Meanwhile, not all the bundlers are compatible with new `/root` API, for example **[parcel](http://parceljs.org/) is not**.
91
92React-Hot-Load will throw an error, asking you to use the old API, if such incompatibility would be detected.
93It is almost the same, but you have to pass `module` inside `hot`.
94
95```js
96import { hot } from 'react-hot-loader';
97const App = () => <div>Hello World!</div>;
98export default hot(module)(App);
99```
100
1013. [Run webpack with Hot Module Replacement](https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr):
102
103```sh
104webpack-dev-server --hot
105```
106
107## Limitations
108
109* (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.
110 As a result - all the code changes, you may made among `componentWillUnmount` or `componentDidMount`, would be ignored for
111 already created components.
112* (that's the goal) React-Hot-Loader would not update any object, including component `state`.
113* (1%) React-Hot-Loader could not reply some changes you may made in components `constructors`. As long as
114 components would not be recreated - RHL have to _inject_ new data onto existing components, but there is no way to detect the actual change and the way reply it.
115 React-Hot-Loader knows what class method is, not how you created it. See #1001 for details.
116
117## Recipes
118
119### Migrating from [create-react-app](https://github.com/facebookincubator/create-react-app)
120
1211. Run `npm run eject`
1222. Install React Hot Loader (`npm install --save-dev react-hot-loader`)
1233. In `config/webpack.config.dev.js`, add `'react-hot-loader/babel'` to Babel
124 loader configuration. The loader should now look like:
125
126```js
127 {
128 test: /\.(js|jsx)$/,
129 include: paths.appSrc,
130 loader: require.resolve('babel-loader'),
131 options: {
132 // This is a feature of `babel-loader` for webpack (not Babel itself).
133 // It enables caching results in ./node_modules/.cache/babel-loader/
134 // directory for faster rebuilds.
135 cacheDirectory: true,
136 plugins: ['react-hot-loader/babel'],
137 },
138 }
139```
140
1414. Mark your App (`src/App.js`) as _hot-exported_:
142
143```js
144// ./containers/App.js
145import React from 'react';
146import { hot } from 'react-hot-loader';
147
148const App = () => <div>Hello World!</div>;
149
150export default hot(module)(App);
151```
152
153### Migrating from [create-react-app](https://github.com/facebookincubator/create-react-app) without ejecting
154
155Users [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.
156
157### TypeScript
158
159As 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.
160
161Fortunately, 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.
162
163A sample configuration:
164
165```js
166{
167 // ...you'll probably need to configure the usual Webpack fields like "mode" and "entry", too.
168 resolve: { extensions: [".ts", ".tsx", ".js", ".jsx"] },
169 module: {
170 rules: [
171 {
172 test: /\.(j|t)sx?$/,
173 exclude: /node_modules/,
174 use: {
175 loader: "babel-loader",
176 options: {
177 cacheDirectory: true,
178 babelrc: false,
179 presets: [
180 [
181 "@babel/preset-env",
182 { targets: { browsers: "last 2 versions" } } // or whatever your project requires
183 ],
184 "@babel/preset-typescript",
185 "@babel/preset-react"
186 ],
187 plugins: [
188 // plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript
189 ["@babel/plugin-proposal-decorators", { legacy: true }],
190 ["@babel/plugin-proposal-class-properties", { loose: true }],
191 "react-hot-loader/babel"
192 ]
193 }
194 }
195 }
196 ]
197 },
198 plugins: [
199 new ForkTsCheckerWebpackPlugin()
200 ]
201};
202```
203
204For 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).
205
206As 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).
207
208### Parcel
209
210Parcel 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).
211
212We also have a [full example running Parcel + React Hot Loader](https://github.com/gaearon/react-hot-loader/tree/master/examples/parcel).
213
214### Electron
215
216You need something to mark your modules as hot in order to use React Hot Loader.
217
218One 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).
219
220A 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.
221
222### Source Maps
223
224If you use `devtool: 'source-map'` (or its equivalent), source maps will be
225emitted to hide hot reloading code.
226
227Source maps slow down your project. Use `devtool: 'eval'` for best build
228performance.
229
230Hot reloading code is just one line in the beginning and one line at the end of
231each module so you might not need source maps at all.
232
233### Linking
234
235If 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.
236
237There are 2 ways to fix `Module not found`:
238
239* 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.
240* Alternatively if you are using webpack, override the module resolution in your config:
241
242```js
243{
244 resolve: {
245 alias: {
246 'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),
247 }
248 }
249}
250```
251
252And 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
253
254```js
255{
256 resolve: {
257 alias: {
258 'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),
259 // add these 2 lines below so linked package will reference the patched version of `react` and `react-dom`
260 'react': path.resolve(path.join(__dirname, './node_modules/react')),
261 'react-dom': path.resolve(path.join(__dirname, './node_modules/react-dom')),
262 // or point react-dom above to './node_modules/@hot-loader/react-dom' if you are using React-🔥-Dom
263 }
264 }
265}
266```
267
268## Preact
269
270React-hot-loader should work out of the box with `preact-compat`, but, in case of pure preact, you will need
271to configure it:
272
273* create configuration file (setupHotLoader.js)
274
275```js
276import reactHotLoader from 'react-hot-loader';
277import preact from 'preact';
278
279reactHotLoader.preact(preact);
280```
281
282* dont forget to import it
283
284#### Preact limitations
285
286* HOCs and Decorators as not supported yet. For Preact React-Hot-Loader v4 behave as v3.
287
288## React Native
289
290React Native
291**[supports hot reloading natively](https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html)**
292as of version 0.22.
293
294Using React Hot Loader with React Native can cause unexpected issues (see #824) and is not recommended.
295
296## Webpack plugin
297
298We 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).
299
300Remember - the `webpack` plugin is **not compatible** with class-based components. The `babel` plugin
301will 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_.
302
303```js
304class MyComponent extends React.Component {
305 onClick = () => this.setState(); // COULD NOT UPDATE
306 variable = 1; // this is ok
307 render() {} // this is ok
308}
309```
310
311But `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).
312
313> It is safe to enable this loader for all the files. But place it after babel-loader, if babel-loader is present.
314
315```js
316// webpack.config.js
317module.exports = {
318 module: {
319 rules: [
320 {
321 test: /\.jsx?$/,
322 include: /node_modules/,
323 use: ['react-hot-loader/webpack'],
324 },
325 ],
326 },
327};
328```
329
330Webpack 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).
331
332### Code Splitting
333
334If you want to use Code Splitting + React Hot Loader, the simplest solution is to pick one of our compatible library:
335
336* [Loadable Components](https://github.com/smooth-code/loadable-components/)
337* [Imported Component](https://github.com/theKashey/react-imported-component)
338* [React Universal Component](https://github.com/faceyspacey/react-universal-component)
339* [React-Loadable](https://github.com/jamiebuilds/react-loadable)
340
341If you use a non-yet-friendly library, like [react-async-component](github.com/ctrlplusb/react-async-component) you have to mark all your "loaded components" as _hot-exported_:
342
343```js
344// AsyncHello.js
345import { asyncComponent } from 'react-async-component';
346
347// asyncComponent could not `hot-reload` itself.
348const AsyncHello = asyncComponent({
349 resolve: () => import('./Hello'),
350});
351
352export default AsyncHello;
353```
354
355```js
356// Hello.js
357import { hot } from 'react-hot-loader';
358
359const Hello = () => 'Hello';
360
361export default hot(module)(Hello); // <-- module will reload itself
362```
363
364### Checking Element `type`s
365
366Because React Hot Loader creates proxied versions of your components, comparing
367reference types of elements won't work:
368
369```js
370const element = <Component />;
371console.log(element.type === Component); // false
372```
373
374React Hot Loader exposes a function `areComponentsEqual` to make it possible:
375
376```js
377import { areComponentsEqual } from 'react-hot-loader';
378const element = <Component />;
379areComponentsEqual(element.type, Component); // true
380```
381
382Another way - compare "rendered" element type
383
384```js
385const element = <Component />;
386console.log(element.type === <Component />.type); // true
387
388// better - precache rendered type
389const element = <Component />;
390const ComponentType = <Component />.type;
391console.log(element.type === ComponentType); // true
392```
393
394But you might have to provide all required props. See [original issue](https://github.com/gaearon/react-hot-loader/issues/304).
395This is most reliable way to compare components, but it will not work with required props.
396
397Another way - compare Component name.
398
399> Not all components has a name. **In production displayName could not exists.**
400
401```js
402const element = <Component />;
403console.log(element.displayName === 'Component'); // true
404```
405
406This is something we did not solve yet. Cold API could help keep original types.
407
408### Webpack ExtractTextPlugin
409
410webpack ExtractTextPlugin is not compatible with React Hot Loader. Please disable it in development:
411
412```js
413new ExtractTextPlugin({
414 filename: 'styles/[name].[contenthash].css',
415 disable: NODE_ENV !== 'production',
416});
417```
418
419#### Disabling a type change (❄️)
420
421It is possible to disable React-Hot-Loader for a specific component, especially to
422enable common way to type comparison.
423See #991 for the idea behind ⛄️, and #304 about "type comparison" problem.
424
425```js
426import { cold } from 'react-hot-loader';
427
428cold(SomeComponent) // this component will ignored by React-Hot-Loader
429<SomeComponent />.type === SomeComponent // true
430```
431
432If you will update `cold` component React-Hot-Loader will complain (on error level), and then
433React will cold-replace Component with a internal state lose.
434
435> Reach-Hot-Loader: cold element got updated
436
437##### Disabling a type change for all node_modules
438
439You 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
440are not welcomed, and modules are not expected to change.
441
442```js
443import { setConfig, cold } from 'react-hot-loader';
444setConfig({
445 onComponentRegister: (type, name, file) => file.indexOf('node_modules') > 0 && cold(type),
446
447 // some components are not visible as top level variables,
448 // thus its not known where they were created
449 onComponentCreate: (type, name) => name.indexOf('styled') > 0 && cold(type),
450});
451```
452
453! To be able to "cold" components from 'node_modules' you have to apply babel to node_modules, while this
454folder is usually excluded.
455You may add one more babel-loader, with only one React-Hot-Loader plugin inside to solve this.
456**Consider using webpack-loader** for this.
457
458##### React-Hooks
459
460React hooks are not _really_ supported by React-Hot-Loader. Mostly due to our internal
461processes of re-rendering React Tree, which is required to reconcile an updated application
462before React will try to rerender it, and fail to do that, obviously.
463
464* hooks **should work** for versions 4.6.0 and above (`pureSFC` is enabled by default).
465* hooks will produce **errors** on every hot-update without patches to `react-dom`.
466* hooks **may loss the state** without patches to `react-dom`.
467* hooks does not support adding new hooks on the fly
468* change in hooks for a mounted components will cause a runtime exception, and a `retry` button (at the nearest class component) will be shown.
469 Pressing a `retry` button will basically remount tree branch.
470
471To mitigate any hook-related issues (and disable their hot-reloadability) - `cold` them.
472
473* _cold_ components using hooks.
474
475```js
476import { setConfig, cold } from 'react-hot-loader';
477setConfig({
478 onComponentCreate: (type, name) =>
479 (String(type).indexOf('useState') > 0 || String(type).indexOf('useEffect') > 0) && cold(type),
480});
481```
482
483## API
484
485### `hot(Component, options)`
486
487Mark a component as hot.
488
489#### Babel plugin
490
491Right now babel plugin has only one option, enabled by default.
492
493* `safetyNet` - will help you properly setup ReactHotLoader.
494
495You may disable it to get more control on the module execution order.
496
497```js
498//.babelrc
499{
500 "plugins": [
501 [
502 "react-hot-loader/babel",
503 {
504 "safetyNet": false
505 }
506 ]
507 ]
508}
509```
510
511#### Important
512
513**!!** Use `hot` only for module `exports`, not for module `imports`. **!!**
514
515```js
516import { hot } from 'react-hot-loader/root';
517
518const App = () => 'Hello World!';
519
520export default hot(App);
521```
522
523Keep in mind - by importing `react-hot-loader/root` you are setting up a boundary for update event propagation.
524
525The higher(in module hierarchy) you have it - the more stuff would be updated on Hot Module Replacement.
526
527To make RHL more reliable and safe, please place `hot` _below_ (ie somewhere in _imported_ modules):
528
529* react-dom
530* redux store creation
531* any data, you want to preserve between updates
532* big libraries
533
534You may(but it's not required) place `hot` to the every route/page/feature/lazy chunk, thus make updates more scoped.
535
536You don't need to wrap every component with `hot`, application work work fine with a single one.
537
538### (old)`hot(module, options)(Component, options)`
539
540Mark a component as hot. The "new" hot is just hidding the first part - `hot(module)`, giving you
541only the second `(App)`. The "new" hot is using old API.
542
543```js
544import { hot } from 'react-hot-loader';
545
546const App = () => 'Hello World!';
547
548export default hot(module)(App);
549```
550
551### `AppContainer`
552
553Mark application as hot reloadable. (**Prefer** using `hot` helper, see below for migration details).
554
555This low-level approach lets you make **hot **imports\_\_, not exports.
556
557```js
558import React from 'react';
559import ReactDOM from 'react-dom';
560import { AppContainer } from 'react-hot-loader';
561import App from './containers/App';
562
563const render = Component => {
564 ReactDOM.render(
565 <AppContainer>
566 <Component />
567 </AppContainer>,
568 document.getElementById('root'),
569 );
570};
571
572render(App);
573
574// webpack Hot Module Replacement API
575if (module.hot) {
576 // keep in mind - here you are configuring HMR to accept CHILDREN MODULE
577 // while `hot` would configure HMR for the CURRENT module
578 module.hot.accept('./containers/App', () => {
579 // if you are using harmony modules ({modules:false})
580 render(App);
581 // in all other cases - re-require App manually
582 render(require('./containers/App'));
583 });
584}
585```
586
587### areComponentsEqual(Component1, Component2)
588
589Test if two components have the same type.
590
591```js
592import { areComponentsEqual } from 'react-hot-loader';
593import Component1 from './Component1';
594import Component2 from './Component2';
595
596areComponentsEqual(Component1, Component2); // true or false
597```
598
599### setConfig(config)
600
601Set a new configuration for React Hot Loader.
602
603Available options are:
604
605* `logLevel`: specify log level, default to `"error"`, available values are: `['debug', 'log', 'warn', 'error']`
606* `pureSFC`: enable Stateless Functional Component. If disabled they will be converted to React Components.
607 Default value: false.
608* `ignoreSFC`: skip "patch" for SFC. "Hot loading" could still work, wit webpack-patch present
609* `pureRender`: do not amend `render` method of any component.
610* for the rest see [index.d.ts](https://github.com/gaearon/react-hot-loader/blob/master/index.d.ts#L62-L133).
611
612```js
613// rhlConfig.js
614import { setConfig } from 'react-hot-loader';
615
616setConfig({ logLevel: 'debug' });
617```
618
619**It is important** to set configuration before any other action will take a place
620
621```js
622// index.js
623import './rhlConfig' // <-- extract configuration to a separate file, and import it in the beggining
624import React from 'react'
625....
626```
627
628## Migrating from v3
629
630### AppContainer vs hot
631
632Prior v4 the right way to setup React Hot Loader was to wrap your Application
633with `AppContainer`, set setup module acceptance by yourself. This approach is
634still valid but only for advanced use cases, prefer using `hot` helper.
635
636**React Hot Loader v3:**
637
638```js
639// App.js
640import React from 'react';
641
642const App = () => <div>Hello world!</div>;
643
644export default App;
645```
646
647```js
648// main.js
649import React from 'react';
650import ReactDOM from 'react-dom';
651import { AppContainer } from 'react-hot-loader';
652import App from './containers/App';
653
654const render = Component => {
655 ReactDOM.render(
656 <AppContainer>
657 <Component />
658 </AppContainer>,
659 document.getElementById('root'),
660 );
661};
662
663render(App);
664
665// webpack Hot Module Replacement API
666if (module.hot) {
667 module.hot.accept('./containers/App', () => {
668 // if you are using harmony modules ({modules:false})
669 render(App);
670 // in all other cases - re-require App manually
671 render(require('./containers/App'));
672 });
673}
674```
675
676**React Hot Loader v4:**
677
678```js
679// App.js
680import React from 'react';
681import { hot } from 'react-hot-loader';
682
683const App = () => <div>Hello world!</div>;
684
685export default hot(module)(App);
686```
687
688```js
689// main.js
690import React from 'react';
691import ReactDOM from 'react-dom';
692import App from './containers/App';
693
694ReactDOM.render(<App />, document.getElementById('root'));
695```
696
697### Patch is optional
698
699> Since 4.0 till 4.8
700
701Code is automatically patched, you can safely remove `react-hot-loader/patch` from your webpack config,
702if react-hot-loader is required before React in any other way.
703
704### Error Boundary is inside every component
705
706> Since 4.5.4
707
708On Hot Module Update we will inject `componentDidCatch` and a _special_ `render`
709to every Class-based component you have, making [Error Boundaries](https://reactjs.org/docs/error-boundaries.html#introducing-error-boundaries) more local.
710
711After update we will remove all sugar, keeping only Boundaries you've created.
712
713You can provide your own `errorReporter`, via `setConfig({errorReporter})` or opt-out from
714root ErrorBoundaries setting `errorBoundary={false}` prop on `AppContainer` or `hot`.
715However - this option affects only SFC behavior, and any ClassComponent would boundary itself.
716
717```js
718import { setConfig } from 'react-hot-loader';
719import ErrorBoundary from './ErrorBoundary';
720
721// ErrorBoundary will be given error and errorInfo prop.
722setConfig({ errorReporter: ErrorBoundary });
723```
724
725If `errorReporter` is not set - full screen error overlay would be shown.
726
727#### Setting global Error Reporter
728
729Global Error Reporter would, created a fixed overlay on top the page,
730would be used to display errors, not handled by `errorReporter`, and
731any HMR error.
732
733You may change, or disable this global error overlay
734
735```js
736// to disable
737setConfig({ ErrorOverlay: () => null });
738
739// to change
740setConfig({ ErrorOverlay: MyErrorOverlay });
741```
742
743The UX of existing overlay is a subject to change, and we are open to any proposals.
744
745## Known limitations and side effects
746
747### Note about `hot`
748
749`hot` accepts only React Component (Stateful or Stateless), resulting the `HotExported` variant of it.
750The `hot` function will setup current module to _self-accept_ itself on reload, and will **ignore** all the changes, made for non-React components.
751You may mark as many modules as you want. But `HotExportedComponent` **should be the only used export** of a _hot_-module.
752
753> Note: Please note how often we have used `exported` keyword. `hot` is for exports.
754
755> Note: Does nothing in production mode, just passes App through.
756
757### New Components keep executing the old code
758
759There is no way to hot-update constructor code, as result even new components
760will be born as the first ones, and then grow into the last ones. As of today, this issue cannot be solved.
761
762## Troubleshooting
763
764If it doesn't work, in 99% of cases it's a configuration issue. A missing option, a
765wrong path or port. webpack is very strict about configuration, and the best way
766to find out what's wrong is to compare your project to an already working setup,
767check out
768**[examples](https://github.com/gaearon/react-hot-loader/tree/master/examples)**,
769bit by bit.
770
771If something doesn't work, in 99% of cases it's an issue with your code. The Component
772didn't get registered, due to HOC or Decorator around it, which is making it
773invisible to the Babel plugin or webpack loader.
774
775We're also gathering
776**[Troubleshooting Recipes](https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md)**
777so send a PR if you have a lesson to share!
778
779### Switch into debug mode
780
781Debug mode adds additional warnings and can tells you why React Hot Loader is
782not working properly in your application.
783
784```js
785import { setConfig } from 'react-hot-loader';
786setConfig({ logLevel: 'debug' });
787```
788
789## Contributors
790
791This project exists thanks to all the people who contribute. [Contribute](CONTRIBUTING.md).
792[![contributors][oc-contributors-img]](https://github.com/gaearon/react-hot-loader/graphs/contributors)
793
794## Backers
795
796Thank you to all our backers! 🙏 [Become a backer][oc-backer-link]
797[![backers][oc-backer-img]][oc-backer-link]
798
799## Sponsors
800
801Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor][oc-sponsor-link]
802
803<a href="https://opencollective.com/react-hot-loader/sponsor/0/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/0/avatar.svg"></a>
804<a href="https://opencollective.com/react-hot-loader/sponsor/1/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/1/avatar.svg"></a>
805<a href="https://opencollective.com/react-hot-loader/sponsor/2/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/2/avatar.svg"></a>
806<a href="https://opencollective.com/react-hot-loader/sponsor/3/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/3/avatar.svg"></a>
807<a href="https://opencollective.com/react-hot-loader/sponsor/4/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/4/avatar.svg"></a>
808<a href="https://opencollective.com/react-hot-loader/sponsor/5/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/5/avatar.svg"></a>
809<a href="https://opencollective.com/react-hot-loader/sponsor/6/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/6/avatar.svg"></a>
810<a href="https://opencollective.com/react-hot-loader/sponsor/7/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/7/avatar.svg"></a>
811<a href="https://opencollective.com/react-hot-loader/sponsor/8/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/8/avatar.svg"></a>
812<a href="https://opencollective.com/react-hot-loader/sponsor/9/website" target="_blank"><img src="https://opencollective.com/react-hot-loader/sponsor/9/avatar.svg"></a>
813
814## License
815
816MIT
817
818[build-badge]: https://img.shields.io/travis/gaearon/react-hot-loader.svg?style=flat-square
819[build]: https://travis-ci.org/gaearon/react-hot-loader
820[coverage-badge]: https://img.shields.io/codecov/c/github/gaearon/react-hot-loader.svg?style=flat-square
821[coverage]: https://codecov.io/github/gaearon/react-hot-loader
822[version-badge]: https://img.shields.io/npm/v/react-hot-loader.svg?style=flat-square
823[package]: https://www.npmjs.com/package/react-hot-loader
824[license-badge]: https://img.shields.io/npm/l/react-hot-loader.svg?style=flat-square
825[license]: https://github.com/gaearon/react-hot-loader/blob/next/LICENSE
826[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
827[prs]: http://makeapullrequest.com
828[chat]: https://gitter.im/gaearon/react-hot-loader
829[chat-badge]: https://img.shields.io/gitter/room/gaearon/react-hot-loader.svg?style=flat-square
830[github-watch-badge]: https://img.shields.io/github/watchers/gaearon/react-hot-loader.svg?style=social
831[github-watch]: https://github.com/gaearon/react-hot-loader/watchers
832[github-star-badge]: https://img.shields.io/github/stars/gaearon/react-hot-loader.svg?style=social
833[github-star]: https://github.com/gaearon/react-hot-loader/stargazers
834[oc-backer-badge]: https://opencollective.com/react-hot-loader/backers/badge.svg
835[oc-sponsor-badge]: https://opencollective.com/react-hot-loader/sponsors/badge.svg
836[oc-contributors-img]: https://opencollective.com/react-hot-loader/contributors.svg?width=890&button=false
837[oc-backer-img]: https://opencollective.com/react-hot-loader/backers.svg?width=890
838[oc-backer-link]: https://opencollective.com/react-hot-loader#backers
839[oc-sponsor-link]: https://opencollective.com/react-hot-loader#sponsor