Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

How to support hot reload? #6

Closed
Lxxyx opened this issue May 11, 2017 · 9 comments
Closed

How to support hot reload? #6

Lxxyx opened this issue May 11, 2017 · 9 comments

Comments

@Lxxyx
Copy link

Lxxyx commented May 11, 2017

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

@jaredpalmer
Copy link

jaredpalmer commented May 12, 2017

Just drop this into your index.tsx

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

@Lxxyx
Copy link
Author

Lxxyx commented May 12, 2017

@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.

@Lxxyx Lxxyx closed this as completed May 12, 2017
@corydeppen
Copy link

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

@jaredpalmer
Copy link

Just add @types/webpack-env

@jaredpalmer
Copy link

@types/webpack-env

@Lxxyx
Copy link
Author

Lxxyx commented May 12, 2017

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

@zikaari
Copy link

zikaari commented May 23, 2017

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

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

@nikhil-advait
Copy link

Hot reload doesn't work for me. I have opened new issue.
#50

@priyanshuchauhan
Copy link

  • 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
);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants