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

Commit 5193249

Browse files
committed
More minimal fix
1 parent 8ebdcab commit 5193249

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/hooks/room/useRoomMemberProfile.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
18-
import { useContext, useEffect, useState } from "react";
18+
import { useContext, useMemo } from "react";
1919

2020
import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext";
2121
import { useSettingValue } from "../useSettings";
@@ -29,18 +29,20 @@ export function useRoomMemberProfile({
2929
member?: RoomMember | null;
3030
forceHistorical?: boolean;
3131
}): RoomMember | undefined | null {
32-
const [member, setMember] = useState<RoomMember | undefined | null>(propMember);
33-
3432
const context = useContext(RoomContext);
3533
const useOnlyCurrentProfiles = useSettingValue("useOnlyCurrentProfiles");
3634

37-
useEffect(() => {
35+
const member = useMemo(() => {
3836
const threadContexts = [TimelineRenderingType.ThreadsList, TimelineRenderingType.Thread];
39-
if ((propMember && !forceHistorical && useOnlyCurrentProfiles)
40-
|| threadContexts.includes(context?.timelineRenderingType)) {
41-
setMember(context?.room?.getMember(userId));
37+
38+
if ((!forceHistorical && useOnlyCurrentProfiles)
39+
|| threadContexts.includes(context.timelineRenderingType)) {
40+
const currentMember = context.room?.getMember(userId);
41+
if (currentMember) return currentMember
4242
}
43-
}, [forceHistorical, propMember, context.room, context?.timelineRenderingType, useOnlyCurrentProfiles, userId]);
43+
44+
return propMember
45+
}, [forceHistorical, propMember, context.room, context.timelineRenderingType, useOnlyCurrentProfiles, userId])
4446

4547
return member;
4648
}

0 commit comments

Comments
 (0)