From 32ab860fbfb31a4401fc8d89e8fe621cb7dbd1ec Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Fri, 15 Nov 2024 12:24:21 +0100 Subject: [PATCH] fix: crash in some instances of useIsChannelMuted hook invocation --- .../components/ChannelPreview/hooks/useIsChannelMuted.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts b/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts index 9b8e87fc3..766b1eecd 100644 --- a/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +++ b/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts @@ -12,18 +12,18 @@ export const useIsChannelMuted = < channel: Channel, ) => { const { client } = useChatContext(); + const initialized = channel?.initialized; - const [muted, setMuted] = useState(channel.muteStatus()); + const [muted, setMuted] = useState(() => initialized && channel.muteStatus()?.muted); useEffect(() => { const handleEvent = () => { - setMuted(channel.muteStatus()); + setMuted(initialized && channel.muteStatus()?.muted); }; client.on('notification.channel_mutes_updated', handleEvent); return () => client.off('notification.channel_mutes_updated', handleEvent); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [muted]); + }, [channel, client, initialized, muted]); return muted; };