Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TobiasWehrum opened this issue Oct 29, 2020 · 4 comments

Comments

@TobiasWehrum
Copy link

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?)

@theKashey
Copy link
Collaborator

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

@TobiasWehrum
Copy link
Author

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

@theKashey
Copy link
Collaborator

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.

@TobiasWehrum
Copy link
Author

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.

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

No branches or pull requests

2 participants