Can anyone explain how to use the macro RCT_EXPORT_MODULE
from React Native to create custom react modules with a specific name that's not the class name?
The documentation says,
This takes an optional argument that specifies the name that the module will be accessible as in your JavaScript code
My class name is:
@implementation ReactCustomService
But I want to rename it to:
RCT_EXPORT_MODULE(@"CustomService")
But this doesn't work. When I do:
var service = NativeModules.CustomService;
nothing is returned. But if I did RCT_EXPORT_MODULE()
, then NativeModules.ReactCustomService
it works fine.
Any thoughts? I also tried RCT_EXPORT_MODULE("CustomService")
, but that doesn't work either.
I'm on react-native: 0.40.0
Integrate the React Native SDK First, go to Setup page, where you can copy your publishable key. In case you are not using React Native, you can refer to the iOS or Android versions. If you want to quickly try the module in a test app, you can use the React Native Quickstart app.
RCT_EXPORT_MODULE is in RCTBridgeModule protocol, You can use this macro to export your iOS module. Place this macro in your class implementation to automatically register your module with the bridge when it loads. The optional js_name argument. It will be used as the JS module name.
pass the name without any quotation marks around, eg.
RCT_EXPORT_MODULE(CustomService)
that should work
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