Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use RCT_EXPORT_MODULE React Native

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

like image 942
Khon Lieu Avatar asked Mar 16 '17 03:03

Khon Lieu


People also ask

How use iOS SDK in React Native?

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.

What is Rct_export_module?

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.


1 Answers

pass the name without any quotation marks around, eg.

RCT_EXPORT_MODULE(CustomService)

that should work

like image 128
vonovak Avatar answered Oct 18 '22 22:10

vonovak