How does one get the value passed to JavaScript's Callback.invoke()

Viewed 46

I can't get value from the following code in JavaScript.

Here my code:

public void isEnabled(Callback isEnabled) {
    isEnabled.invoke(wifi.isWifiEnabled());
}

How do I get at the return value of the expression wifi.isWifiEnabled() in JavaScript (react-native)?

1 Answers

Your example code is part of the library's implementation. To get the value passed to invoke, consume the module at its API level.

WifiManager.isEnabled(bool => {/* do stuff with wifi enabled */})

If you need this as a promise, you can create your own isWifiEnabled that returns a Promise

const isWifiEnabled = () => new Promise(resolve => {
  WifiManager.isEnabled(bool => resolve(bool))
})

isWifiEnabled().then(bool => {/* stuff with wifi enabled */})
Related