Typescript-react-starter: How to support hot reload?

Created on 11 May 2017  路  9Comments  路  Source: microsoft/TypeScript-React-Starter

This project is useful, but how to use hot reload?

Most helpful comment

@types/webpack-env

All 9 comments

Just drop this into your index.tsx

if (module.hot) {
  module.hot.accept();
}

@jaredpalmer Thank you. Simple and useful. But when hot reload start, component state will be set to default state, how to resolve this problem?
May be I should stackoverflow this problem first.

@jaredpalmer Unfortunately, this will cause a compilation error since the latest typings for node don't include a hot property on the NodeModule type.

Just add @types/webpack-env

@types/webpack-env

or you can use (module as any).hot.accept() @corydeppen

Maybe you're looking for this, since you mentioned losing state

https://github.com/gaearon/react-hot-loader

Hot reload doesn't work for me. I have opened new issue.
https://github.com/Microsoft/TypeScript-React-Starter/issues/50

  • npm install react-hot-loader --save-dev
  • npm install --save-dev @types/webpack-env

In index.tsx:

(module as any).hot.accept();

ReactDOM.render(
  <App />,
  document.getElementById('root') as HTMLElement
);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

haani104 picture haani104  路  5Comments

ghost picture ghost  路  7Comments

user135711 picture user135711  路  6Comments

a455047 picture a455047  路  8Comments

wongjiahau picture wongjiahau  路  9Comments