useParticipantAttribute
function useParticipantAttribute(attributeKey, options?): string;Defined in: packages/react/src/hooks/participant/useParticipantAttribute.ts:40
The useParticipantAttribute hook returns the latest value of a given attribute key of a participant. It requires a Participant object passed as property in the UseParticipantAttributesOptions or via the ParticipantContext.
Parameters
| Parameter | Type |
|---|---|
attributeKey | string |
options? | UseParticipantAttributeOptions |
Returns
string
Example
// Basic — read one participant attribute.
const role = useParticipantAttribute("role");
// Advanced — show a participant's role inside a participant tile.
function ParticipantRole({ participant }: { participant: Participant }) {
const role = useParticipantAttribute("role", { participant });
const { identity } = useParticipantInfo({ participant });
return <span>{identity}: {role || "guest"}</span>;
}
function Roster() {
const participants = useParticipants();
return <>{participants.map((participant) => <ParticipantRole key={participant.identity} participant={participant} />)}</>;
}
function App() {
return <VoiceRoom agent={agent}><Roster /></VoiceRoom>;
}