Skip to content

Commit 015ddf4

Browse files
authored
Improve hmr experience for react components (#104)
* improve hmr experience for react components * fix hmr for async module
1 parent b4fc95b commit 015ddf4

File tree

6 files changed

+88
-8
lines changed

6 files changed

+88
-8
lines changed

package-lock.json

Lines changed: 79 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"raw-loader": "^4.0.2",
5858
"react-axe": "^3.5.4",
5959
"react-docgen-typescript-loader": "^3.7.2",
60+
"react-hot-loader": "^4.13.0",
6061
"react-router-dom": "^5.2.0",
6162
"regenerator-runtime": "^0.13.7",
6263
"rimraf": "^3.0.2",
@@ -80,7 +81,7 @@
8081
"@patternfly/react-icons": "^4.7.11",
8182
"@patternfly/react-styles": "^4.7.8",
8283
"react": "^16.14.0",
83-
"react-dom": "^16.14.0",
84+
"react-dom": "npm:@hot-loader/react-dom@^16.14.0",
8485
"react-router-last-location": "^2.0.1",
8586
"sirv-cli": "^1.0.8"
8687
}

src/app/Support/Support.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { hot } from 'react-hot-loader/root';
23
import { CubesIcon } from '@patternfly/react-icons';
34
import {
45
PageSection,
@@ -15,7 +16,7 @@ export interface ISupportProps {
1516
sampleProp?: string;
1617
}
1718

18-
const Support: React.FunctionComponent<ISupportProps> = () => (
19+
let Support: React.FunctionComponent<ISupportProps> = () => (
1920
<PageSection>
2021
<EmptyState variant={EmptyStateVariant.full}>
2122
<EmptyStateIcon icon={CubesIcon} />
@@ -39,4 +40,5 @@ const Support: React.FunctionComponent<ISupportProps> = () => (
3940
</PageSection>
4041
)
4142

43+
Support = hot(Support); // enable HMR for this async module
4244
export { Support };

src/app/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { hot } from 'react-hot-loader/root';
12
import * as React from 'react';
23
import '@patternfly/react-core/dist/styles/base.css';
34
import { BrowserRouter as Router } from 'react-router-dom';
@@ -13,4 +14,4 @@ const App: React.FunctionComponent = () => (
1314
</Router>
1415
);
1516

16-
export { App };
17+
export default hot(App);

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import { App } from '@app/index';
3+
import App from '@app/index';
44

55
if (process.env.NODE_ENV !== "production") {
66
const config = {

webpack.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = env => {
99

1010
return {
1111
entry: {
12-
app: path.resolve(__dirname, 'src', 'index.tsx')
12+
app: ['react-hot-loader/patch', path.resolve(__dirname, 'src', 'index.tsx')]
1313
},
1414
module: {
1515
rules: [

0 commit comments

Comments
 (0)