Skip to main content

React Native Native Modules with Example: Traditional Way vs TurboModules (2025 Guide)

React Native Native Modules with Example: Traditional vs TurboModules (2025)

React Native provides powerful capabilities to communicate with platform-specific code using Native Modules. With the new TurboModules architecture, this process becomes more efficient, performant, and memory-friendly. In this blog, we’ll explore both the traditional and TurboModules approaches, compare them, and provide code examples.


๐Ÿ“š What is a Native Module in React Native?

Native Modules allow you to write platform-specific functionality in Java (Android) or Objective-C/Swift (iOS) and expose it to your React Native JavaScript code.


⚙️ Traditional Native Modules (Old Architecture)

In the traditional model, native modules are registered using ReactPackage and invoked via the bridge (async communication).

๐Ÿงช Android Example (Java)

// MyModule.java
public class MyModule extends ReactContextBaseJavaModule {
  public MyModule(ReactApplicationContext context) {
    super(context);
  }

  @Override
  public String getName() {
    return "MyModule";
  }

  @ReactMethod
  public void showMessage(String msg) {
    Toast.makeText(getReactApplicationContext(), msg, Toast.LENGTH_SHORT).show();
  }
}
// MyPackage.java
public class MyPackage implements ReactPackage {
  @Override
  public List createNativeModules(ReactApplicationContext context) {
    return Arrays.asList(new MyModule(context));
  }
}
// MainApplication.java
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.asList(new MainReactPackage(), new MyPackage());
}

๐Ÿงช JS Call

import { NativeModules } from 'react-native';
NativeModules.MyModule.showMessage("Hello from Native!");

๐Ÿš€ TurboModules (Modern Architecture)

TurboModules use JSI for direct, synchronous access and are code-generated with type safety via TypeScript interfaces.

๐Ÿงฉ Step 1: Define Spec

// MyModule.ts (TypeScript)
export interface Spec extends TurboModule {
  showMessage(msg: string): void;
}
export default Spec;

⚙️ Step 2: Implement in C++/Java (Android)

// MyModule.cpp (C++)
jsi::Value MyModule::showMessage(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
  std::string msg = args[0].asString(rt).utf8(rt);
  // platform call to show toast...
  return jsi::Value::undefined();
}

๐Ÿ“ฆ Step 3: Register Module

// MyModuleProvider.java
@ReactModule(name = MyModule.NAME)
public class MyModule extends TurboReactPackage {
  ...
}

๐Ÿ”— Step 4: Use in JS

import MyModule from 'react-native/Libraries/BatchedBridge/NativeModules';
MyModule.showMessage("Hello via TurboModule!");

๐Ÿ†š Traditional vs TurboModules: Key Differences

FeatureTraditionalTurboModules
BridgeAsync via JSONDirect via JSI
PerformanceSlowerMuch faster
CodegenManual interfaceTyped via TypeScript
Lazy loadingNoYes
Memory UsageHigherLower

๐Ÿง  Final Thoughts

TurboModules are the future of native module development in React Native. While traditional modules are still supported, it’s highly recommended to adopt TurboModules for better performance and type safety—especially in modern apps using the New Architecture (Fabric, JSI, Hermes).

Want to migrate your traditional modules to TurboModules? Start by defining typed interfaces in TypeScript, and let Codegen handle the native scaffolding for you.

๐Ÿ’ก Pro Tip: TurboModules shine in performance-critical features like sensors, Bluetooth, camera, and background tasks.

Comments

Popular posts from this blog

⚠️ React Native 0.79 (New Architecture) – Common Issues & Quick Fixes

React Native 0.79 (New Architecture) – Common Issues & Fixes With React Native 0.79 (part of Expo SDK 53 ), the New Architecture — which includes TurboModules , Fabric , and JSI — is now enabled by default. While this delivers better performance and platform-native alignment, many developers are encountering critical issues while upgrading or starting fresh projects. ๐Ÿ” Brief: What’s Going Wrong? 1. Third-Party Library Crashes Libraries like react-native-maps or @stripe/stripe-react-native might crash due to incompatibility with TurboModules or Fabric rendering. 2. Build & Runtime Errors Common issues include build failures related to CMake, Hermes, or JSI, and runtime UI bugs — especially on Android with edge-to-edge layout behavior. 3. Component Rendering Issues Blank screens, flickering components, or gesture conflicts due to changes in how the new rendering system manages views. ✅ Solutions & Fixes 1...

Edge-to-Edge UI in Android with React Native: How to Do It Right (2025 Update)

Intro Starting from 2024-25, Android apps are expected to embrace edge-to-edge UI — where your app content flows behind the system bars (status bar, navigation bar) for a fully immersive experience. Google is pushing for it hard, and React Native (especially with New Architecture and Expo SDK 53+) has made it much easier to implement. In this blog, I’ll walk you through: ✅ Why edge-to-edge matters for modern Android apps ✅ How to implement it correctly in React Native (Expo & Bare projects) ✅ Handling tricky parts like keyboard, gestures, and safe areas ✅ Real-world gotchas I ran into — and how to fix them Why Edge-to-Edge? Modern Android design guidelines (Material You) heavily prefer edge-to-edge layouts. It makes apps feel more native, more immersive, and makes better use of larger phone screens. Plus, starting Android 15, apps that don't adopt it might feel noticeably "outdated". How to Do It in React Native ๐Ÿš€ ...

React Native Expo (2025 Edition)

Expo in React Native: Everything You Need to Know (2025 Edition) Everything You Need to Know About Expo in 2025 ๐Ÿš€ Expo is a framework and platform for universal React applications. It simplifies the development and deployment process of React Native apps with powerful tools and services. As of 2025, Expo has matured into an all-in-one toolkit that supports everything from development to distribution. ๐Ÿ“ฆ What is Expo? Expo is a set of tools built around React Native to help you build native iOS, Android, and web apps using JavaScript and React. It removes native dependencies, making it easier for JavaScript developers to build and deploy native apps quickly. ๐Ÿงฐ Key Services Provided by Expo Expo Go: Preview your app without needing to build a native binary. Expo Dev Client: Customizable development client for testing native modules. EAS Build: Build your app in the cloud for iOS and Android. EAS Submit: Submit builds to...