babel-plugin-functional-hmr
Babel plugin enables HMR for functional components in React Native.
A Babel plugin that fixes hot reloading for functional components in React Native, so code changes show up instantly during development.
Plain-English Explanation: babel-plugin-functional-hmr
When you're developing a React Native app, you want to see your code changes instantly without restarting the entire app. This feature is called hot module reloading (HMR). The problem is that React Native's HMR has never worked properly for functional components — the ones written as simple JavaScript functions that return UI. You'd see "hot loading" messages, but your changes wouldn't actually appear on screen. This plugin fixes that problem.
The plugin works by transforming your functional components into class-based components behind the scenes, then wrapping them with special HMR code. When you save a file, the build system can now properly detect and hot-reload your changes. You don't see this transformation — it happens automatically during development. The README includes an example showing how an arrow function component gets converted to a class component with HMR wrappers, so the development tools can track changes properly.
This is useful if you're building a React Native mobile app and want a smoother development experience. Every time you tweak a button's color, text, or layout, you'll see the change instantly instead of waiting for a full app reload. You set it up by adding the plugin to your Babel configuration file, and it only runs during development, not in production.
There are some limitations worth knowing: the plugin only works with functional components written as arrow functions (not class components), and it doesn't support React Hooks. If you're using Hooks in your components, this won't help you — you'll run into errors. Also, if you change your Babel config, you need to restart the packager with a cache reset for the changes to take effect, which can be a gotcha when troubleshooting.
Where it fits
- See UI tweaks like color or layout changes appear instantly while developing a React Native app
- Add this plugin to a Babel config to fix broken hot module reloading for functional components
- Speed up the dev feedback loop when you're not yet using React Hooks
- Debug why HMR isn't reflecting changes by understanding the class-component transform it does