React native push notification handling

Viewed 235

I have successfully set up local push notifications for android with react-native and react-native-push-notification`. I have read countless articles by now and all of them only explained the setup part that is already working for me and decided to omit the whole controlling the App part.

My onNotification (defined in my index.js) function is getting called as expected and I am getting console logs.

However, this is not really helpful in any way, as I am outside of the App component.

I am trying to get the data inside of the App component.

Idea 1: Put the whole setup code in a function and call it in a use effect from App`. I have read multiple times that the setup has to be done outside of lifecycles, as it leads to issues if done within them.

Idea 2: Global variable hacking is like setting a global callback. I have decided against this for obvious reasons like globals generally being a bad idea and this obviously being a hack.

I am at the end of my wisdom here. While I am going to use a hacky solution, for now, I would be very happy about your input.

TLDR: How do I get info from a callback outside of App into App?

0 Answers
Related