useParticipantAttributes
function useParticipantAttributes(props?): {
attributes: Readonly<Record<string, string>> | undefined;
};Defined in: packages/react/src/hooks/participant/useParticipantAttributes.ts:35
A reactive React primitive.
Parameters
| Parameter | Type |
|---|---|
props? | UseParticipantAttributesProps |
Returns
{
attributes: Readonly<Record<string, string>> | undefined;
}attributes
attributes: Readonly<Record<string, string>> | undefined;Example
// Basic — read all attributes for the current participant context.
const { attributes } = useParticipantAttributes();
// Advanced — render all known attributes for a participant.
function ParticipantAttributes({ participant }: { participant: Participant }) {
const { attributes } = useParticipantAttributes({ participant });
return <>{Object.entries(attributes ?? {}).map(([key, value]) => <span key={key}>{key}: {value}</span>)}</>;
}
function Roster() {
const participants = useParticipants();
return <>{participants.map((participant) => <ParticipantAttributes key={participant.identity} participant={participant} />)}</>;
}
function App() {
return <VoiceRoom agent={agent}><Roster /></VoiceRoom>;
}