steep-balloon-41261
09/11/2023, 2:52 PMpolite-kilobyte-67570
09/11/2023, 2:54 PM<ParticipantLoop>
<ParticipantName />
</ParticipantLoop>freezing-ocean-2185
09/11/2023, 2:54 PMeager-zoo-16408
09/11/2023, 2:57 PMuseParticipants hook to get the participants and pass it into the ParticipantLoop:
const participants = useParticipants();
<ParticipantLoop participants={participants}>
<ParticipantName />
<ParticipantLoop />polite-kilobyte-67570
09/11/2023, 2:57 PMfreezing-ocean-2185
09/12/2023, 8:54 AMimport { LiveKitRoom, VideoConference, RoomContext, ConnectionQualityIndicator, ControlBar, useParticipants, ParticipantLoop, ParticipantName } from '@livekit/components-react';
const room = useMemo(() => new Room(), []);
const participants = useParticipants();
return (
<main data-lk-theme="default" style={{ width: '100%', height: '100%' }}>
<LiveKitRoom
room={room}
token={tokenUserLK}
serverUrl={devUrl}
connect={true}
audio={true}
video={true}
onConnected={() => {
console.log("done");
}}
>
<VideoConference />
<ParticipantLoop participants={participants}>
<ParticipantName />
</ParticipantLoop>
</LiveKitRoom>
</main>
);
};
having this line const participants = useParticipants(); it crashes the application
here's the error :
react-dom.production.min.js:189 Error: No room provided, make sure you are inside a Room context or pass the room explicitly
at fC (room-context.ts:37:11)
at TC (useRemoteParticipants.ts:26:16)
at NC (useParticipants.ts:24:30)
hooks.tsx:608 React Router caught the following error during render Error: No room provided, make sure you are inside a Room context or pass the room explicitly
at fC (room-context.ts:37:11)
at TC (useRemoteParticipants.ts:26:16)
at NC (useParticipants.ts:24:30)
please help me if you have an ideaeager-zoo-16408
09/12/2023, 9:01 AMuseParticipants() hook depends on the room context. To get the room context, you need to use the hook inside the <LiveKitRoom> component.
An easy way to do this is to create a React component like this:
function MyParticipantList(){
const participants = useParticipants();
return (
<ParticipantLoop participants={participants}>
<ParticipantName />
</ParticipantLoop>
)
}
and then use it as a child of LiveKitRoom:
<LiveKitRoom
room={room}
token={tokenUserLK}
serverUrl={devUrl}
connect={true}
audio={true}
video={true}
onConnected={() => {
console.log("done");
}}
>
<VideoConference />
<MyParticipantList />
</LiveKitRoom>freezing-ocean-2185
09/12/2023, 9:02 AMeager-zoo-16408
09/12/2023, 9:03 AM