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

Commit

Permalink
avoid ref by getting count in setter callback
Browse files Browse the repository at this point in the history
  • Loading branch information
bwindels committed Mar 4, 2020
1 parent afc7273 commit 4437310
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/components/views/right_panel/UserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,18 @@ function useIsEncrypted(cli, room) {
}

function useHasCrossSigningKeys(cli, member, canVerify, setUpdating) {
// use a ref to setUpdating because we don't want to rerun
// the useAsyncMemo hook when it changes.
const updatingRef = useRef();
useEffect(() => {
updatingRef.current = setUpdating;
}, [setUpdating]);

return useAsyncMemo(async () => {
if (!canVerify) {
return false;
}
updatingRef.current(true);
setUpdating(true);
try {
await cli.downloadKeys([member.userId]);
const xsi = cli.getStoredCrossSigningForUser(member.userId);
const key = xsi && xsi.getId();
return !!key;
} finally {
updatingRef.current(false);
setUpdating(false);
}
}, [cli, member, canVerify], false);
}
Expand Down Expand Up @@ -1356,9 +1349,9 @@ const BasicUserInfo = ({room, member, groupId, devices, isRoomEncrypted}) => {
homeserverSupportsCrossSigning &&
isRoomEncrypted && !userVerified && !isMe;

const setUpdating = useCallback((updating) => {
setPendingUpdateCount(pendingUpdateCount + (updating ? 1 : -1));
}, [setPendingUpdateCount, pendingUpdateCount]);
const setUpdating = (updating) => {
setPendingUpdateCount(count => count + (updating ? 1 : -1));
};
const hasCrossSigningKeys =
useHasCrossSigningKeys(cli, member, canVerify, setUpdating );

Expand Down

0 comments on commit 4437310

Please sign in to comment.