bug: Channel list component never updates custom handler for onMessageNewHandler
#2524
Labels
bug
Something isn't working
released on @latest
status:confirmed
Described issue has been reproduced by the repo maintainer
Describe the bug
We're using component
ChannelList
and passing some custom event handlers (eg.onMessageNewHandler
). That component uses hookuseMessageNewListener
to subscribe tomessage.new
event and run some internal logic or to run custom event handler. Internally, hook usesuseEffect
to manage event subscription but sincecustomHandler
prop is not in effect's dependecies, it never updates it so we're always stuck with the inital event callback version which then contains stale component state.To Reproduce
Steps to reproduce the behavior:
ChannelList
component and pass it that event handler inonMessageNewHandler
propertymessage.new
eventExpected behavior
When an event handler for
ChannelList.onMessageNewHandler
changes (eg. becauseuseCallback()
dependecies chaged), component should update and use the latest handler version on next appropriate event.Package version
Desktop (please complete the following information):
Additional context
v12.0.0 - https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/hooks/useMessageNewListener.ts#L51
v11.23.10 - https://github.com/GetStream/stream-chat-react/blob/v11.23.10/src/components/ChannelList/hooks/useMessageNewListener.ts#L51
The text was updated successfully, but these errors were encountered: