gaearon / react-hot-loader

Tweak React components in real time. (Deprecated: use Fast Refresh instead.)

Home Page:http://gaearon.github.io/react-hot-loader/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Explain in Troubleshooting.md why "const anyModule = module as any;" doesn't work as expected

TobiasWehrum opened this issue · comments

At https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md, you say that

const anyModule = module as any;
if (anyModule.hot) {
  anyModule.hot.accept('./app', () => render(App));
}

will lead to full page reloads, but

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

will work. I am pretty confused by that, as I'd expect both to lead to the same result. Not understanding it makes it harder to remember too.

Could you maybe add to the document why it is behaving like this?

(Or if you don't have the time to do that at the moment, give me a hint here?)

I am pretty sure this example was not updated in past 4 years, so just not trust it 😅

Haha. Fair! But I'm still pretty curious as to why those two would be (have been in the past?) any different.

Nowadays you should not use any module.hot in terms of React-Hot-Loader at all - there is react-hot-loader/root which does under the hood.

Don't worry, I know that. I was more wondering as to what language feature I am missing that makes these two examples any different.