when i click on a notification , messaging().onNotificationOpenedApp function calling multiple times
useEffect(() => {
messaging().onNotificationOpenedApp(async remoteMessage => {
if (remoteMessage) {
const notification =
JSON.parse(String(remoteMessage.data));
const notificationData = NotificationMapper([notification]);
await notificationNavigation(notificationData[0]);
}
})}, []);
this is my code ,please help me out to prevent calling above function multiple times
you're missing the listener remover when your component gets unmounted
useEffect(() => {
// assign the listener to a variable
const listener = messaging().onNotificationOpenedApp(async remoteMessage => {
if (remoteMessage) {
const notification = JSON.parse(String(remoteMessage.data));
const notificationData = NotificationMapper([notification]);
await notificationNavigation(notificationData[0]);
}
})
// and remove it when your component gets unmounted
return () => listener()
}, []);
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