Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native 0.47.1: Hot reload is not reflecting code changes on MacOS

I'm trying to get hot reload working with my React Native project. The packager shows the message Bundling index.ios.js ... [hmr enabled] and when I make a change, i see the Hot reloading... message flash on the device so I'm confident that the change is being detected. However, the actual screen is not reflecting the code changes. Live reload works fine.

I've reinstalled the node modules and reset/uninstalled/reinstalled watchman. Nothing seems to have any effect.

What else should I be trying? How do I figure out why the screen isn't being updated?

like image 554
Bill Avatar asked Sep 02 '17 11:09

Bill


People also ask

Is this an issue with React-Native reloading?

This is definitely an issue with the new react-native reload feature as no matter which debugger I use, this seems to occur randomly. I'd also like some feedback from the team, just to know if they could quickly take a look at it.

How to enable hot reloading on Redux stores using React-transform?

The default transformer that comes with React Native uses the babel-preset-react-native, which is configured to use react-transform the same way you'd use it on a React web project that uses Webpack. To enable Hot Reloading on Redux stores you will just need to use the HMR API similarly to what you'd do on a web project that uses Webpack:

Why can't I hot-reload my react app?

This could be due to your filesystem, file extensions or the Create-React-App default webpack/project configuration. You don't necessarily have to change all of this because hot-reloading is supposed to work out of the box, and more so if the project has just started.

Does hot reloading work with index JS?

But further down from index.js in a component, hot reloading does appear to be working. That is the correct answer!! Just put the logic code elsewhere, index.js is only responsible for quoting.


1 Answers

The current version of hmr in react-native only works for components that extend from React.Component or Component [see]. In other words, it doesn't work for functional components or components that extend another base class.

  • For functional components you can use babel-plugin-functional-hmr.
  • If you have a custom base class, you can override react-transform plugin in your .babelrc as the following:

    {
      "presets": ["react-native"],
      "env": {
        "development": {
          "plugins": [
            ["react-transform",
              {
                "transforms": [{
                  "transform": "react-transform-hmr",
                  "imports": ["react"],
                  "locals": ["module"]
                }],
                "superClasses": ["CustomComponent", "React.Component", "Component"]
              }
            ]
          ]
        }
      }
    }
    
like image 147
muratakbal Avatar answered Sep 26 '22 17:09

muratakbal