Hot reloading (HMR) not working with functional components
See original GitHub issueDescription
Hot reloading doesn’t work on functional components. The “hot loading” message appears, but the changes don’t show up.
Reproduction
react-native init test
cd test
Open index.android.js and replace :
export default class test extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
}
}
with
const test = () => (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
Enable hot reloading, reload the app and try to make changes.
Additional Information
- React Native version: 0.37.0
- Platform: Android (didn’t try ios)
- Operating System: Windows
Issue Analytics
- State:
- Created 7 years ago
- Reactions:67
- Comments:53 (12 by maintainers)
Top Results From Across the Web
HMR not triggering sometimes for components - Stack Overflow
Hot reloading always works for files; index.js , App.jsx , & routes/index.jsx but sometimes it will work for views/Dashboard/index.
Read more >Stateless Components and Hot Module Reloading · Mobx Doc
In this case, ToDoItem is stateless, but will still work with HMR because the root-level of the UI tree is a stateful observer....
Read more >Hot Module Replacement - webpack
This is happening because the button's onclick event handler is still bound to the original printMe function. To make this work with HMR...
Read more >Hot Reload | Vue Loader
"Hot Reload" is not simply reloading the page when you edit a file. With hot reload enabled, when you edit a *.vue file,...
Read more >React Fast Refresh — The New React Hot Reloader
In addition, React Fast Refresh's state preservation does not work for class components — it only works with function components and hooks.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
This has been fixed on master with a new implementation we’re calling Fast Refresh. https://mobile.twitter.com/reactnative/status/1144629612921720833
It will be a part of the 0.61 release. I’m going to close this issue.
+1