Hooks
Hooks are functions that you can call inside theme components to access data. When the data changes, the component will automatically re-render with the new data.
Here's an example component that lists the names of up to 10 participants in a conversation.
1import { html, useParticipants } from "@talkjs/react-components";23export function MyComponent({ common }) {4 const participants = useParticipants(common.conversation.id, 10);56 return html`<div>7 ${participants.map(p => html`<span key=${p.user.id}>${p.user.name}</span>`)}8 </div>`;9}
useParticipants(conversationId, limit): ParticipantSnapshot[]
Returns a list of participants in the conversation with the given ID. It subscribes to the participants, updating them as people join or leave, and automatically unsubscribes when the calling component unmounts.
Parameters
ID of the conversation
Maximum number of participants to subscribe to. Defaults to 10. The maximum is 100.
Returns
List of participant snapshots.