# Function off(event: string, callback: (payload: any) =\> void): void; Is this "off" function working?

**URL:** <https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097>\
**Category:** Web\
**Created:** [May 12, 2021, 7:58am UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097 "2021-05-12T07:58:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joecodingjourney](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joecodingjourney](https://devforum.zoom.us/u/joecodingjourney)\
**Post date:** [May 12, 2021, 7:58am UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097/1 "2021-05-12T07:58:18Z")

</div>

Version: zoom video sdk 1.0.3

I have the following code:

`this.zoomClient.on('active-share-change', (resp) => this.onActiveShareChange(resp));`

Then, I implemented this “off” event:

`this.zoomClient.off('active-share-change', (resp) => this.onActiveShareChange(resp));`

then, when the page starts, I call “on” again

`this.zoomClient.on('active-share-change', (resp) => this.onActiveShareChange(resp));`

Now, I have 2 events coming in every time there is someone shares the screen.

I wonder if the “ **off** ” is functioning properly. Or, my “off” implementation is not correct.

Can you please let me know?

Thanks,

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [May 12, 2021, 8:26am UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097/2 "2021-05-12T08:26:35Z")

</div>

Hey @joecodingjourney

Thanks for sharing your questions.

You can use a variable or function to save the event handler, use the inline arrow function will create different functions, so it seems `off` function not working.

---

<div class="post-metadata">

**Author:** ![joecodingjourney](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joecodingjourney](https://devforum.zoom.us/u/joecodingjourney)\
**Post date:** [May 12, 2021, 2:54pm UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097/3 "2021-05-12T14:54:04Z")

</div>

Hi Vic,

So, instead of doing the inline arrow, you mean that I should do this instead

`this.zoomClient.on('active-share-change', this.onActiveShareChange(resp));`  
`this.zoomClient.off('active-share-change', this.onActiveShareChange(resp));`

Or, can you please give me a code example with using a variable or function to save the event handler?

Thanks

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [May 13, 2021, 1:25am UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097/4 "2021-05-13T01:25:08Z")

</div>

Hey @joecodingjourney

If you need to use `this` in the `onActiveShareChange` method, you should bind `this` first, use `this.onActiveShareChange = this.onActiveShareChange.bind(this)`, then pass the function as the parameter:

```
this.zoomClient.on('active-share-change', this.onActiveShareChange);
this.zoomClient.off('active-share-change', this.onActiveShareChange);

```

Thanks.  
Vic

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [June 12, 2021, 11:26am UTC](https://devforum.zoom.us/t/function-off-event-string-callback-payload-any-void-void-is-this-off-function-working/50097/5 "2021-06-12T11:26:00Z")

</div>

Closed on June 12, 2021, 11:26am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
