React UI Kit: Add User Event Handler

Hi,

I am trying to follow the steps from this sendbird tutorial for adding a user event handler to the sdk

however, when I try to do something similar ; for instance, the following:

 useEffect(() => {
        if (sdk) {
            const userEventHandler: UserEventHandler = new UserEventHandler({
                onTotalUnreadMessageCountUpdated: (totalCount, countByCustomTypes) => {
                    console.log('onTotalUnreadMessageCountUpdated', totalCount, countByCustomTypes);
                },
            });
            sdk.addUserEventHandler('customEventTesting', userEventHandler);
        }
    }, [sdk]);

I’m getting the following error:

TypeError: sdk.addUserEventHandler is not a function

we are using the following npm packages:

"@sendbird/chat": "^4.2.3",
"@sendbird/uikit-react": "^3.3.3",

any ideas on how we can get this to work?

ultimately, we are trying to accomplish two things:

  1. get the count of unread messages
  2. send an email for each message sent

Thank you!

1 Like

Related to this, I tried using useTotalUnreadMessageCount() from @sendbird/uikit-chat-hooks but it does not react to new messages arriving; I need to create a badge elsewhere in the application that reacts to new messages arriving, so we can call the users’ attention.

I’ve also tried using this as well:

const handlerId = useUniqHandlerId('useTotalUnreadMessageCount');
useUserEventHandler(sdk, handlerId, {
  onTotalUnreadMessageCountChanged: countChanged => console.log('onTotalUnreadMessageCountChanged', countChanged),
  onTotalUnreadMessageCountUpdated: totalCount => console.log('onTotalUnreadMessageCountUpdated deprecated', totalCount),
});