Repository navigation
Update docs and samples to use REACT_TURBO_MODULE as the default - #1155
Open
Harini Malothu (HariniMalothu17) wants to merge 1 commit into
Open
Harini Malothu (HariniMalothu17) wants to merge 1 commit into
Harini Malothu (HariniMalothu17) wants to merge 1 commit into
Conversation
Harini Malothu (HariniMalothu17)
requested a review
from a team
as a code owner
February 24, 2026 08:04
Contributor
|
It would be better , if you added the screenshot of the example app of this turbo module |
Vladimir Morozov (vmoroz)
force-pushed
the
user/FixDocsNativeModules
branch
from
October 23, 2026 14:17
66c2d73 to
e74193e
Compare
There was a problem hiding this comment.
🟡 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
| 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. |
| ``` | ||
|
|
||
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Updates documentation and sample code to recommend
REACT_TURBO_MODULEoverREACT_MODULEfor native modules.REACT_TURBO_MODULEis required when usingREACT_EVENTwithNativeEventEmitterin JavaScript, and should be the default for all new modules.REACT_MODULEis 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