Skip to content

Commit

Permalink
get webpack HMR working
Browse files Browse the repository at this point in the history
  • Loading branch information
jokester committed Apr 17, 2018
1 parent 10e5dd0 commit 92df62e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions browser-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ import App from './App';
import './index.css';
import registerServiceWorker from './registerServiceWorker';

function registerHMR() {
type ModuleHMR = typeof module & {
hot?: {
accept(dependencies: string | string[], callback: (updatedDependencies: any[]) => void): void
}
};

if ((module as ModuleHMR).hot) {
(module as ModuleHMR).hot!.accept('./App', () => {
ReactDOM.render(
<App />,
document.getElementById('root') as HTMLElement
);
});
}
}

ReactDOM.render(
<App />,
document.getElementById('root') as HTMLElement
);
registerServiceWorker();
registerHMR();

2 comments on commit 92df62e

@lookfirst
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've duplicated your render(). Abstract to function.

@jokester
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lookfirst fixed here and in PR 👍

Please sign in to comment.