RCT_EXPORT_METHOD that takes no parameters and returns a promise throws error
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
yes
Environment
Environment: OS: macOS Sierra 10.12.6 Node: 8.9.0 Yarn: 1.3.2 npm: 5.5.1 Watchman: 4.9.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.0 AI-171.4408382
Packages: (wanted => installed) react: 16.0.0-beta.5 => 16.0.0-beta.5 react-native: 0.49.3 => 0.49.3
Target Platform: iOS (10.3)
Steps to Reproduce
(Write your steps here:)
- Create a native module that returns a promise
TestNativeModule.h
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface TestNativeModule : NSObject <RCTBridgeModule>
@end
TestNativeModule.m
@implementation TestNativeModule
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(get: findEventsWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
resolve("test");
}
@end
- Call it from JS:
const promise = NativeModules.CallToAdventureNative.get();
- See the error:
CallToAdventureNative.get was called with 0 arguments but expects 1 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.
Note: It works if you pass Anything to the .get function.
Expected Behavior
It would call the function.
Actual Behavior
The error posted above.
Reproducible Demo
It’s a native module, can’t repro the web
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to bridge React Native Promise to Swift - Stack Overflow
I am currently working on a React native project for which I need to add some logic which has been written in swift....
Read more >Promise.prototype.then() - JavaScript - MDN Web Docs
The then() method of a Promise object takes up to two arguments: ... Makes .then() return a rejected promise throw new Error("Oh no!...
Read more >iOS Native Modules
Let's follow the example below and call RCT_EXPORT_MODULE without any arguments. As a result, the module will be exposed to React Native ...
Read more >Error handling with promises - The Modern JavaScript Tutorial
new Promise((resolve, reject) => { throw new Error("Whoops! ... alert(`The unknown error has occurred: ${error}`); // don't return anything ...
Read more >Why Promise.all doesn't reject when a non-promise throws an ...
It takes an array of promises as its argument and returns a single ... elements (passed as an argument to Promise.all()) throws an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try:
I’m just checking in on this. I’m also running into this error. Is there a better solution than that empty string hack?