Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove firebase.notifications().onNotificationOpened listener?

I am working on a react native project and using react-native-firebase library. Setting up listener is working but I am not able to find a way to remove listener.

I am setting up this listener on homepage so whenever user reach to homepage. Listener get registered multiple times and action multiple times as result.

I want to destroy this listener then again start a new one.

firebase.notifications().onNotificationOpened((notificationOpen) => {
        if (notificationOpen) {
          const notification: Notification = notificationOpen.notification;
          if(notification.data.type){
          }
        }
      });

If anyone can help, that will be appreciated...

like image 952
Aditya Batra Avatar asked Feb 18 '26 16:02

Aditya Batra


1 Answers

You need to call the listener again in order to remove it as mentioned in the docs.

componentDidMount() {
    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
          //... Your Stuff
   }
}

componentWillUnmount() {
    this.notificationOpenedListener();
}
like image 89
Pritish Vaidya Avatar answered Feb 21 '26 14:02

Pritish Vaidya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!