gaearon / react-hot-loader

Tweak React components in real time. (Deprecated: use Fast Refresh instead.)
http://gaearon.github.io/react-hot-loader/
MIT License
12.26k stars 801 forks source link

Not work with typescipt please help #493

Closed und3fined closed 7 years ago

und3fined commented 7 years ago

Description

I've converted your code to run features HMR, but not work. I get full browser logs.

Screen 1 IMG1

Screen 2 IMG2

Screen 3 IMG3

Environment

React Hot Loader version: "react-hot-loader": "next",

Run these commands in the project folder and fill in their results:

  1. node -v: v6.10.0
  2. npm -v: v3.10.10
  3. yarn --version: v0.21.3

Then, specify:

  1. Operating system: mac OS 10.12.3
  2. Browser and version: Version 55.0.2883.95 (64-bit)

Reproducible Demo

My repo: https://github.com/und3fined/react-hot-ts

und3fined commented 7 years ago

Now it work. You can clone the repo and test. I change

import App from './App';

const rootEl = document.getElementById('root');
const render = (Component: any) => {
    ReactDOM.render(<AppContainer><Component /></AppContainer>, rootEl)
};

render(App);

if (module.hot) {
    module.hot.accept('./App', () => render(App))
}

to


import App from './App';

const rootEl = document.getElementById('root');
const render = (Component: any) => {
    ReactDOM.render(<AppContainer><Component /></AppContainer>, rootEl)
};

render(App);

if (module.hot) {
    module.hot.accept('./App', () => {

        // I do not know why!
        // if without this line, the hot reload not work!!!
        // no document for this issue.
        const NextApp = require("./App").default; 

        // You can use 'App' or 'NextApp'
        render(NextApp);
    });
}
ghost commented 7 years ago

This is odd!

This actually goes against the docs.

So I wonder if the docs are wrong?

ghost commented 7 years ago

Could be related to https://github.com/gaearon/react-hot-loader/issues/514#issuecomment-288482049