### Promises #### React ```js async function loadVideo() { try { var videoLoaded = await VideoPlayer.loadVideo(); this.setState(videoLoaded: videoLoaded) } catch (e) { console.error(e) } } loadVideo() ``` #### iOS [docs](http://facebook.github.io/react-native/releases/next/docs/native-modules-ios.html#promises) ```obj-c RCT_REMAP_METHOD(loadVideo, loadVideoWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { BOOL videoLoaded = ...; // could be any data type listed under https://facebook.github.io/react-native/docs/native-modules-ios.html#argument-types if (videoLoaded) { resolve(videoLoaded); } else { NSError *error = ... reject(@"error", @"error description", error); } } ``` #### Android [docs](https://facebook.github.io/react-native/docs/native-modules-android.html#promises) ```java @ReactMethod loadVideo(Promise promise) { try { Boolean videoLoaded = ...; // could be any data type listed under https://facebook.github.io/react-native/docs/native-modules-android.html#argument-types if (videoLoaded) { promise.resolve(videoLoaded); } } catch (Exception e) { promise.reject(ERROR, e); } } ``` [__Go to Top__](https://gist.github.com/chourobin/f83f3b3a6fd2053fad29fff69524f91c#file-0-bridging-react-native-cheatsheet-md)