在 React Native 的 componentWillUnmount 中执行异步任务?

Hen*_*all 5 reactjs react-native

我正在尝试在 React Native 中卸载组件之前断开蓝牙设备的连接。断开连接是异步完成的。下面的方法不是断开设备。我怎样才能让它工作?

我想这与断开连接是异步完成的事实有关。

componentWillUnmount(){
   BluetoothManager.disconnect(device); // working properly in other contexts.
}
Run Code Online (Sandbox Code Playgroud)