# Event handlers like user-added apparently execute callback upon creation regardless of event

**URL:** <https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232>\
**Category:** Web\
**Created:** [October 1, 2021, 12:20am UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232 "2021-10-01T00:20:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![StackRef](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/stackref/32/31516_2.png) [@StackRef](https://devforum.zoom.us/u/StackRef)\
**Post date:** [October 1, 2021, 12:20am UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232/1 "2021-10-01T00:20:13Z")

</div>

**Description**  
When I create event handlers for user add, remove, update, it appears the callback function executes immediately upon the handler being created.

**Browser Console Error**  
The callback function gets called when zoomClient.on(‘user-added’, callback) (and any other handler related to users) is created, even if a user was not added.

**Which Web Video SDK version?**  
1.1.5

**Video SDK Code Snippets**  
` useEffect(() => { console.log(':: useParticipantsChange: useEffect'); zoomClient.on('user-added', () => callback('joined')); zoomClient.on('user-removed', () => callback('left')); zoomClient.on('user-updated', () => callback('updated')); return () => { zoomClient.off('user-added', callback); zoomClient.off('user-removed', callback); zoomClient.off('user-updated', callback); }; }, [zoomClient, callback]);`

**To Reproduce(If applicable)**  
Steps to reproduce the behavior:

1. Reload page
2. ALL of the event handlers get triggered immediately, but then also execute as expected on subsequent, real events.

**Screenshots**  
Apparently I can’t embed?

**Device (please complete the following information):**

- Device: MacBook Pro
- OS: MacOS
- Browser: Chrome
- Browser Version: Latest

**Additional context**  
As you can see, I want to update a status message only when a user joins, leaves or is updated. The screenshot shows when I first initiate the session – all three get triggered. If someone joins later, I get the proper “joined” message.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [October 1, 2021, 10:37pm UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232/2 "2021-10-01T22:37:05Z")

</div>

Hey @StackRef , thanks for posting and using the Video SDK! 🙂

> [@StackRef](#):
>
> ALL of the event handlers get triggered immediately

Upon reload this is expected as a reload emulates a disconnection, and then reconnection. Although, it does not sound right that `user-updated` would also trigger.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![StackRef](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/stackref/32/31516_2.png) [@StackRef](https://devforum.zoom.us/u/StackRef)\
**Post date:** [October 3, 2021, 2:45pm UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232/3 "2021-10-03T14:45:19Z")

</div>

I believe `user-updated` might trigger because it considers updating the user device information and hosting status as an update. Just a guess.

By “reload” do you mean the DOM is regenerated (using React), or a full page reload?

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [October 4, 2021, 4:19pm UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232/4 "2021-10-04T16:19:19Z")

</div>

Hey @StackRef ,

> [@StackRef](#):
>
> I believe `user-updated` might trigger because it considers updating the user device information and hosting status as an update. Just a guess.

That sound correct.

> [@StackRef](#):
>
> By “reload” do you mean the DOM is regenerated (using React), or a full page reload?

A full page reload like you mentioned:

> [@StackRef](#):
>
> **To Reproduce(If applicable)**  
> Steps to reproduce the behavior:
> 
> 1. Reload page
> 2. ALL of the event handlers get triggered immediately, but then also execute as expected on subsequent, real events.

Thanks,  
Tommy

---

<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:** [November 4, 2021, 2:19am UTC](https://devforum.zoom.us/t/event-handlers-like-user-added-apparently-execute-callback-upon-creation-regardless-of-event/58232/5 "2021-11-04T02:19:35Z")

</div>

Closed on November 4, 2021, 2:19am UTC

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