My goal is to get the data from a method. The method return a Promise<BluetoothDevice[]>
.
I would like to create a 2nd method to invoke the 1st method. The 2nd method should not return a Promise, instead it should return the data immediately.
This is the interface
interface BluetoothModule { getBondedDevices(): Promise<BluetoothDevice[]>;}
This is how I plan to use it.
const App = () => { const bluetoothList = BluetoothModule.getBondedDevices(); console.log(bluetoothList); return <Text>Hello, this is what the user see.</Text>}
What I've tried
- Create a global method.
const getBondedDevices = async () => await BluetoothModule.getBondedDevices(); // This returns Promise<BluetoothDevice[]>
- Create a global method
const getBondedDevices = BluetoothModule.getBondedDevices();const App = () => { const bluetoothList = getBondedDevices; // this returns the list, somehow... I find it weird. I will post the log below. const bluetoothList2 = BluetoothModule.getBondedDevices(); // this does not return the list. console.log(bluetoothList); console.log(bluetoothList2); return <Text>This is what the user see</TexT>}
This is the log for the 2nd method
{"_U": 0, "_V": 1, "_W": [{"address": "00:13:04:84:03:07", "isConnected": false, "name": "BTHP1"}, {"address": "00:13:04:84:03:6F", "isConnected": false, "name": "BTHP1"}], "_X": null}{"_U": 0, "_V": 0, "_W": null, "_X": null}