Skip to content

Update docs and samples to use REACT_TURBO_MODULE as the default - #1155

Open
Harini Malothu (HariniMalothu17) wants to merge 1 commit into
mainfrom
user/FixDocsNativeModules
Open

Harini Malothu (HariniMalothu17) wants to merge 1 commit into
mainfrom
user/FixDocsNativeModules

Conversation

@HariniMalothu17

@HariniMalothu17 Harini Malothu (HariniMalothu17) commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Updates documentation and sample code to recommend REACT_TURBO_MODULE over REACT_MODULE for native modules. REACT_TURBO_MODULE is required when using REACT_EVENT with NativeEventEmitter in JavaScript, and should be the default for all new modules.

REACT_MODULE is retained in docs only where it is explicitly described as legacy (for older RN versions that lack native TurboModule event emitters).

Resolves #1154

Screenshots

Add any relevant screen captures here from before or after your changes.

Microsoft Reviewers: Open in CodeFlow

@vineethkuttan

Copy link
Copy Markdown
Contributor

It would be better , if you added the screenshot of the example app of this turbo module

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The event-subscription examples remain incompatible with the new annotation, and the registration guidance incorrectly describes the effect of passing false.

2 open issues
What changed in this PR

This PR makes REACT_TURBO_MODULE the recommended annotation for new C++ native modules in the samples and documentation, addressing the event-emitter discoverability problem in #1154.

Changes:

  • Migrates three C++ sample modules to REACT_TURBO_MODULE.
  • Updates native-module tutorials and examples to recommend the annotation.
  • Revises current and version-0.80 guidance on legacy modules, events, and registration.
File Description
website/​versioned_docs/​version-0.80/​native-modules.md Updates versioned annotation and registration guidance.
samples/​NativeModuleSample/​cpp-lib/​windows/​NativeModuleSample/​SimpleHttpModule.h Migrates the HTTP sample annotation.
samples/​NativeModuleSample/​cpp-lib/​windows/​NativeModuleSample/​FancyMath.h Migrates the math sample annotation.
samples/​NativeModuleSample/​cpp-lib/​windows/​NativeModuleSample/​DataMarshallingExamples.h Migrates the data-marshalling sample annotation.
docs/​native-platform-modules.md Updates the Turbo Native Module walkthrough.
docs/​native-modules.md Updates annotation, event, and registration guidance.
docs/​native-modules-async.md Updates the asynchronous module example annotation.

Review effort: Balanced

Comment thread docs/native-modules.md
The `REACT_MODULE` macro-attribute says that the class is a React Native native module. It receives the class name as a first parameter. All other macro-attributes also receive their target as a first parameter. `REACT_MODULE` has an optional parameter for the module name visible to JavaScript and optionally the name of a registered event emitter. By default, the name visible to JavaScript is the same as the class name, and the default event emitter is `RCTDeviceEventEmitter`.
The `REACT_TURBO_MODULE` macro-attribute says that the class is a React Native TurboModule. It receives the class name as a first parameter. All other macro-attributes also receive their target as a first parameter. `REACT_TURBO_MODULE` has an optional parameter for the module name visible to JavaScript. By default, the name visible to JavaScript is the same as the class name.

> **NOTE:** Use `REACT_TURBO_MODULE` for all new native modules. It is required when your module uses `REACT_EVENT` and you want to subscribe to events via `NativeEventEmitter` in JavaScript. `REACT_MODULE` is legacy support for older React Native versions that lack native TurboModule event emitters — use it only when targeting older RN versions.
Comment thread docs/native-modules.md
```

Here we've implemented the `CreatePackage` method, which receives `packageBuilder` to build contents of the package. Since we use macros and templates to discover and bind native module, we call `AddAttributedModules` function to register all native modules in our DLL that have the `REACT_MODULE` macro-attribute. Specifying true here will register all the native modules as TurboModules rather than Native Modules. This will avoid some additional serialization that happens with Native Module calls. If for some reason you need the modules to continue to run as Native Modules, you can specify false here.
Here we've implemented the `CreatePackage` method, which receives `packageBuilder` to build contents of the package. Since we use macros and templates to discover and bind native module, we call `AddAttributedModules` function to register all native modules in our DLL that have the `REACT_TURBO_MODULE` or `REACT_MODULE` macro-attribute. Specifying `true` here registers all modules as TurboModules, which avoids additional serialization overhead. If you need modules to run as legacy Native Modules, you can pass `false` — but this is not recommended for new code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs] Improve Turbo Module docs for EventEmitter

4 participants