Skip to content

Commit

Permalink
fix: crash in some instances of useIsChannelMuted hook invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Nov 15, 2024
1 parent 81507fb commit 32ab860
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export const useIsChannelMuted = <
channel: Channel<StreamChatGenerics>,
) => {
const { client } = useChatContext<StreamChatGenerics>();
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;
};

0 comments on commit 32ab860

Please sign in to comment.