Skip to content

Commit 32ab860

Browse files
committed
fix: crash in some instances of useIsChannelMuted hook invocation
1 parent 81507fb commit 32ab860

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ export const useIsChannelMuted = <
1212
channel: Channel<StreamChatGenerics>,
1313
) => {
1414
const { client } = useChatContext<StreamChatGenerics>();
15+
const initialized = channel?.initialized;
1516

16-
const [muted, setMuted] = useState(channel.muteStatus());
17+
const [muted, setMuted] = useState(() => initialized && channel.muteStatus()?.muted);
1718

1819
useEffect(() => {
1920
const handleEvent = () => {
20-
setMuted(channel.muteStatus());
21+
setMuted(initialized && channel.muteStatus()?.muted);
2122
};
2223

2324
client.on('notification.channel_mutes_updated', handleEvent);
2425
return () => client.off('notification.channel_mutes_updated', handleEvent);
25-
// eslint-disable-next-line react-hooks/exhaustive-deps
26-
}, [muted]);
26+
}, [channel, client, initialized, muted]);
2727

2828
return muted;
2929
};

0 commit comments

Comments
 (0)