Skip to content

[Question]: Why does my addEventListener("Click") keeps re-firing even after removeEventListener? #1860

@Purblac

Description

@Purblac

How can we help?

I have an issue when I notification is being clicked.

The issue is that every time i close app , the click keeps re-firing even when I already add a removeEventListener.


 

useEffect(() => {
    if (ENV_ONE_SIGNAL_ID) {
      // OneSignal Initialization
      OneSignal.initialize(ENV_ONE_SIGNAL_ID);

  
      OneSignal.Notifications.requestPermission(true);

      OneSignal.Notifications.addEventListener(
        "foregroundWillDisplay",
        handleForegroundWillDisplay
      );

      //Method for handling notifications opened

      OneSignal.Notifications.addEventListener(
        "click",
        handleNotificationClick
      );

      return () => {
        OneSignal.Notifications.removeEventListener(
          "foregroundWillDisplay",
          handleForegroundWillDisplay
        );
        OneSignal.Notifications.removeEventListener(
          "click",
          handleNotificationClick
        );
      };
    }
  }, []);

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions