question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hot reloading (HMR) not working with functional components

See original GitHub issue

Description

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:closed
  • Created 7 years ago
  • Reactions:67
  • Comments:53 (12 by maintainers)

github_iconTop GitHub Comments

41reactions
gaearoncommented, Jun 28, 2019

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.

17reactions
shahen94commented, Feb 19, 2017

+1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found