I know that are a similar question here (React Native - Global Event Listener), but my App.js is not a component itself, instead is where I initialize the Navigation (react-native-navigation) with a component and redux.
My question is: How I could call redux actions from Bluetooth listener if I'm not inside any component yet?
const store = configureStore();
Navigation.registerComponent("printerapp.ExampleScreen", () => ExampleScreen);
Navigation.registerComponent(
"printerapp.SelectPrinterScreen",
() => props => (
<Provider store={store}>
<SelectPrinterScreen {...props} />
</Provider>
),
() => SelectPrinterScreen
);
Navigation.registerComponent(
"printerapp.SharePlaceScreen",
() => props => (
<Provider store={store}>
<SharePlaceScreen {...props} />
</Provider>
),
() => SharePlaceScreen
);
// ... other component registrations.
BluetoothSerial.on("bluetoothDisabled", () => {
alert("Bluetooth Disabled");
// HERE WANT TO DISPATCH REDUX ACTION
// BUT I DONT KNOW HOW MAKE THAT IF THAT IS NOT A COMPONENT
});
// Start app
export default () => {
Navigation.setRoot({
root: {
stack: {
children: [
{
component: {
name: "printerapp.SelectPrinterScreen"
}
}
],
options: {
topBar: {
title: {
text: "Bluetooth printer"
}
}
}
}
}
});
}