Skip to content

Commit

Permalink
Return memo'ed participants array from useParticipants hook (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Apr 17, 2024
1 parent ecef222 commit 2da35e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lucky-cherries-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Use participant array length to re-trigger sorting
6 changes: 5 additions & 1 deletion packages/react/src/hooks/useParticipants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Room, RoomEvent } from 'livekit-client';
import { useLocalParticipant } from './useLocalParticipant';
import { useRemoteParticipants } from './useRemoteParticipants';
import * as React from 'react';

/** @public */
export interface UseParticipantsOptions {
Expand Down Expand Up @@ -34,5 +35,8 @@ export function useParticipants(options: UseParticipantsOptions = {}) {
const remoteParticipants = useRemoteParticipants(options);
const { localParticipant } = useLocalParticipant(options);

return [localParticipant, ...remoteParticipants];
return React.useMemo(
() => [localParticipant, ...remoteParticipants],
[localParticipant, remoteParticipants],
);
}

0 comments on commit 2da35e7

Please sign in to comment.