Beacon API Docs
  • Beacon - Installation
  • Beacon - Usage
    • Beacon Usage - Overview
    • Usage in a Next.js Environment
    • Open and Close Programmatically
  • Native Routing in Beacon
    • Vanilla JS - Native Routing Example
    • React JS - Native Routing Example
    • Vue JS - Native Routing Example
    • Angular JS - Native Routing Example
  • Loading User Data into BeaconBar
  • Loading Session Data into Beacon Bar
  • Callbacks in Beacon
    • Add Callbacks in Beacon
    • Remove Callbacks in Beacon
    • React Example for Callbacks
  • Trigger smart journeys From Your App
  • Execute Command From Your App
  • Open Help Docs From Your App
  • Emitting Events to Beacon
  • Listening to events from Beacon Bar
    • Adding event listeners in Beacon
    • Removing event listeners in Beacon
    • React Example for Event Listeners in Beacon
  • List of events emitted by Beacon Bar
  • Implementing Content Security Policy (CSP) for Beacon Integration
Powered by GitBook
On this page
  1. Listening to events from Beacon Bar

Removing event listeners in Beacon

When you've added event listeners to listen to analytical events emitted by Beacon Bar, you may want to remove those listeners at some point to prevent further event handling. Removing event listeners is important for managing your application's resources and ensuring that no unnecessary event handling occurs.

Removing an Event Listener

To remove an event listener, you can use the Beacon.removeEventListener method. This method takes one parameter:

  • func (function): The reference to the event listener function that you want to remove.

Here's how to use it:

import {Beacon} from '@beacon.li/bar';
Beacon.removeEventListener(func);

Use Cases

Removing event listeners can be beneficial for scenarios such as:

  • Cleanly managing resources and preventing memory leaks.

  • Turning off event handling when it's no longer needed, improving application performance.

  • Ensuring that event listeners do not interfere with other parts of your application.

Important Considerations

When removing event listeners, make sure you pass the exact reference to the event listener function that you want to remove. It's important to remove the correct listener to avoid unexpected behavior in your application.

By following these steps, you can effectively remove event listeners added with @beacon.li/bar, helping you maintain clean and efficient event handling in your application.

PreviousAdding event listeners in BeaconNextReact Example for Event Listeners in Beacon

Last updated 1 year ago