From 7e0e082194bc6aac3b4dc4df556010f36897ae32 Mon Sep 17 00:00:00 2001 From: eswarclynn Date: Mon, 14 Aug 2023 17:28:55 +0530 Subject: [PATCH] fix: move up initialisation --- .../src/Prebuilt/components/EqualProminence.jsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/EqualProminence.jsx b/packages/roomkit-react/src/Prebuilt/components/EqualProminence.jsx index b572491483..904e5124a3 100644 --- a/packages/roomkit-react/src/Prebuilt/components/EqualProminence.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/EqualProminence.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { useMeasure, useMedia } from 'react-use'; import { getPeersWithTiles, @@ -30,6 +30,7 @@ export function EqualProminence() { const [pagesWithTiles, setPagesWithTiles] = useState([]); const [page, setPage] = useState(0); const [ref, { width, height }] = useMeasure(); + const peersSorter = useMemo(() => new PeersSorter(vanillaStore), [vanillaStore]); const pageSize = pagesWithTiles[0]?.length; useEffect(() => { @@ -127,17 +128,12 @@ export function EqualProminence() { if (page !== 0) { return; } - const peersSorter = new PeersSorter(vanillaStore); peersSorter.setPeersAndTilesPerPage({ peers, tilesPerPage: pageSize || maxTileCount, }); peersSorter.onUpdate(setSortedPeers); - - return () => { - peersSorter.stop(); - }; - }, [page, vanillaStore, peers, pageSize, maxTileCount]); + }, [page, peersSorter, peers, pageSize, maxTileCount]); return (