I have a listener registered in my Pairing
screen that calls a method whenever the connected Bluetooth device gets disconnected
// Pairing.js
const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);
componentDidMount() {
this.handlerDisconnected = bleManagerEmitter.addListener(
"BleManagerDisconnectPeripheral",
this.handlePeripheralDisconnected
);
}
componentWillUnmount() {
this.handlerDisconnected.remove();
}
I want this event all across my app, how can I create a global event listener and not have to copy paste this code across every screen?
p.s I am using react-native-ble-manager and redux+sagas if that helps
Add the listener in your top level component (App.js)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With