# onMessageReceived handler throws Unhandled Promise warning

**URL:** <https://community.sendbird.com/t/onmessagereceived-handler-throws-unhandled-promise-warning/4227>\
**Category:** JavaScript\
**Tags:** react-js, chatsdk\
**Created:** [March 21, 2022, 7:27am UTC](https://community.sendbird.com/t/onmessagereceived-handler-throws-unhandled-promise-warning/4227 "2022-03-21T07:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [March 21, 2022, 7:27am UTC](https://community.sendbird.com/t/onmessagereceived-handler-throws-unhandled-promise-warning/4227/1 "2022-03-21T07:27:19Z")

</div>

Hi, I’m receiving this warning whenever `onMessageReceived` is triggered

```auto
LogBox.js:173 Possible Unhandled Promise Rejection (id: 7):
TypeError: Cannot read property 'onMessageReceived' of undefined
TypeError: Cannot read property 'onMessageReceived' of undefined

```

The only thing that my `onMessageReceived` handler do is to update the list of messages if the received channel is the current channel. This is the code that does the updating:

```auto
setMessages(items => [message, ...items]);

```

If I remove this line, the warning goes away.

This warning is blocking me because I have two `onMessageReceived` handlers registered separately in two components but as soon as the first handler gets this warning, the second one wouldn’t run.

What’s weird is that the warning does not happen to `onMessageUpdated` and `onMessageDeleted` although they have almost the same logic inside.

Would appreciate some help here.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [March 21, 2022, 6:22pm UTC](https://community.sendbird.com/t/onmessagereceived-handler-throws-unhandled-promise-warning/4227/2 "2022-03-21T18:22:46Z")

</div>

Hi @hewong,

Thank you for reaching out. Could you tell me what version of the JavaScript SDK you’re utilizing? Additionally, could you show me how you’re registering your channel handlers?  
Also, I just want to clarify that when you remove `setMessages`, the error goes away?

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [March 22, 2022, 2:08am UTC](https://community.sendbird.com/t/onmessagereceived-handler-throws-unhandled-promise-warning/4227/4 "2022-03-22T02:08:09Z")

</div>

I’m using version 3.1.8 of the SDK.

I think it could’ve been caused by the use of `uuid()` as the channel handler id, which changes every time the component re-renders. Looks like the warning goes away if I hardcode a unique string as the id.

Let me double check, will update here again if it still happens.
