Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
remove useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain committed Aug 31, 2023
1 parent ab420ca commit f37b29f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/hooks/useRoomMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { useCallback, useMemo, useState } from "react";
import { useMemo, useState } from "react";
import { Room, RoomEvent, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { throttle } from "lodash";

Expand Down Expand Up @@ -55,20 +55,16 @@ export const useRoomMemberCount = (room: Room, opts: RoomMemberCountOpts = { thr

const { throttleWait } = opts;

const updateMembershipCount = useCallback((): void => {
setCount(room.getJoinedMemberCount());
}, [room]);

const throttledUpdate = useMemo(
() =>
throttle(
() => {
updateMembershipCount();
setCount(room.getJoinedMemberCount());
},
throttleWait,
{ leading: true, trailing: true },
),
[throttleWait, updateMembershipCount],
[room, throttleWait],
);

useTypedEventEmitter(room.currentState, RoomStateEvent.Members, throttledUpdate);
Expand Down

0 comments on commit f37b29f

Please sign in to comment.