-
Notifications
You must be signed in to change notification settings - Fork 801
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
Lose state while using TypeScript without Babel #923
Comments
For now we rely on Babel to make React Hot Loader work. I am sorry, but you have to add Babel if you want to use it. |
Babel is not required to preserve the state, only to properly propagate updates. |
@theKashey Yeah really? Maybe I made mistakes some where. I'm really appreciate if you have time to help checking the code! Here's it: https://github.com/nonoroazoro/typescript-react-boilerplate You can run I've put a button on the page, you can click it and then modify |
@neoziro Thanks anyway! |
Your code is 100% fine. It does not work due some optimizations I've added :( How to solve? Add to the require('react-hot-loader').default.register(() => {}, 'a','b'); Anywhere. This code will just got executed on hot-module-replacement, and inform RHL about that event. Look like it is time to bring back webpack loader :) |
@theKashey Got it. I'll try this and wait for your good news. Thanks again for helping me understanding this issue~ 😸 You're right, it's worked!!! 😆 |
Even better - you can add this code to the index.tsx. Just right before ReactDOM.render |
Yep, I'll do it :) |
@nonoroazoro did you get it working? Im interested in this issue as well. |
I've just played with your example, and fixed it with 3 lines, I've added to App.tsx (no changes in index.tsx) import {hot} from 'react-hot-loader';
...... // all the file
declare const module: any;
export default hot(module)(App); |
@pleerock Yes it worked~ and I've put some comments about the HMR in my source code. @theKashey Thanks again! 😄 Actually I've already seen this api while I'm searching for the |
|
Would be great to support this out of the box, there are lot of people using typescript that will face this problem |
We can’t. If we will try to hot reload code on each render - it will ruin everything. |
|
@theKashey I finally solved the // Add hook to auto re-render the root component.
@hot(module)
export default class App extends PureComponent
{
render()
{
return (
<div className={styles.app}>
<Counter />
</div>
);
}
} In addition, it also solved the It's perfect! I love this |
Ok. I should update Readme :) |
Environment (without Babel):
Expected behavior
HMR with state preserved.
Actual behavior
HMR worked, while the state is lost.
Upgraded Environment (with Babel):
react-hot-loader/babel
in.babelrc
Now I get HMR with state preserved, but I really don't want to add Babel to my TypeScript project.
What I expected is to have a full HMR without adding Babel. Are there ways around this? Thanks!
The text was updated successfully, but these errors were encountered: