@@ -15,7 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import { RoomMember } from "matrix-js-sdk/src/models/room-member" ;
18
- import { useContext , useEffect , useState } from "react" ;
18
+ import { useContext , useMemo } from "react" ;
19
19
20
20
import RoomContext , { TimelineRenderingType } from "../../contexts/RoomContext" ;
21
21
import { useSettingValue } from "../useSettings" ;
@@ -29,18 +29,20 @@ export function useRoomMemberProfile({
29
29
member ?: RoomMember | null ;
30
30
forceHistorical ?: boolean ;
31
31
} ) : RoomMember | undefined | null {
32
- const [ member , setMember ] = useState < RoomMember | undefined | null > ( propMember ) ;
33
-
34
32
const context = useContext ( RoomContext ) ;
35
33
const useOnlyCurrentProfiles = useSettingValue ( "useOnlyCurrentProfiles" ) ;
36
34
37
- useEffect ( ( ) => {
35
+ const member = useMemo ( ( ) => {
38
36
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
42
42
}
43
- } , [ forceHistorical , propMember , context . room , context ?. timelineRenderingType , useOnlyCurrentProfiles , userId ] ) ;
43
+
44
+ return propMember
45
+ } , [ forceHistorical , propMember , context . room , context . timelineRenderingType , useOnlyCurrentProfiles , userId ] )
44
46
45
47
return member ;
46
48
}
0 commit comments