onMessageReceived handler throws Unhandled Promise warning

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

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:

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.

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?

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.