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?
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.
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:
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.
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.
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.
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"] } ] ] } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With