Skip to content

Commit 1f3e929

Browse files
committed
fix: properly initialize unread state
1 parent d69c30c commit 1f3e929

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

examples/SampleApp/src/components/UnreadCountBadge.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ export const ChannelsUnreadCountBadge: React.FC = () => {
4242
if (event.total_unread_count !== undefined) {
4343
setUnreadCount(event.total_unread_count);
4444
} else {
45-
const countUnread = Object.values(chatClient.activeChannels).reduce(
46-
(count, channel) => count + channel.countUnread(),
47-
0,
48-
);
49-
setUnreadCount(countUnread);
45+
if (Object.keys(chatClient?.activeChannels).length > 0) {
46+
const countUnread = Object.values(chatClient.activeChannels).reduce(
47+
(count, channel) => count + channel.countUnread(),
48+
0,
49+
);
50+
setUnreadCount(countUnread);
51+
}
5052
}
5153
});
5254

0 commit comments

Comments
 (0)