api.removeListener does not seem to unsubscribe from events

I have subscribed to ‘toolbarButtonClicked’ event as shown below

this.api.addListener(‘toolbarButtonClicked’, (data) => { });

Once call is ended, I unsubscribe from this event as shown below

this.api.removeListener(‘toolbarButtonClicked’, (data) => { });

But I never receive a callback event.

Also when I subscribe again next time without reloading web page, I get 2 callbacks.

Is there any workaround?

How about:

const toolbarButtonClickedHandler = (data) => {
  // ..

api.addListener(‘toolbarButtonClicked’, toolbarButtonClickedHandler);
// ...
api.removeListener(‘toolbarButtonClicked’, toolbarButtonClickedHandler);

In your example, you’re creating a new anonymous function in the removeListener param which won’t match what you previously added.

Not sure I understand. Why would you expect to receive a callback event after unsubscribing?