ParticipantContextIfNeeded
function ParticipantContextIfNeeded(__namedParameters): Element;Defined in: packages/react/src/components/participant/ParticipantContextIfNeeded.tsx:39
The ParticipantContextIfNeeded component only creates a ParticipantContext if there is no ParticipantContext already.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | ParticipantContextIfNeededProps |
Returns
Element
Example
// Basic — add participant context only when one is missing.
<ParticipantContextIfNeeded participant={participant}>
<ParticipantName />
</ParticipantContextIfNeeded>
// Advanced — keep participant children working inside and outside loops.
function RosterNames() {
const participants = useParticipants();
return (
<VoiceRoom agent={agent}>
<ParticipantLoop participants={participants}>
<ParticipantContextIfNeeded><ParticipantName /></ParticipantContextIfNeeded>
</ParticipantLoop>
</VoiceRoom>
);
}