For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
useUnreads
Get the list of conversations with unread messages.
The useUnreads hook allows you to get a list of conversations with unread messages.
It needs to be a used in a descendant of the <Session> component.
The hook returns an array of UnreadConversation objects,
or undefined if the hook is used outside of a <Session> object, or if the session gets destroyed. (In particular, this often happens in development due to things like hot module reloading).
This example component uses the useUnreads hook to render a <span> containing the number of conversations with unread messages.
import { useUnreads } from '@talkjs/react';
function UnreadConversationsCounter(props) {
const unreads = useUnreads(); // Talk.UnreadConversation[] | undefined
if (!unreads) {
return null;
}
return <span className="unreads-count">{unreads.length}</span>;
}