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

Commit 8a964db

Browse files
committed
avoid ref by getting count in setter callback
1 parent afc7273 commit 8a964db

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/components/views/right_panel/UserInfo.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
1717
limitations under the License.
1818
*/
1919

20-
import React, {useCallback, useMemo, useState, useEffect, useContext, useRef} from 'react';
20+
import React, {useCallback, useMemo, useState, useEffect, useContext} from 'react';
2121
import PropTypes from 'prop-types';
2222
import classNames from 'classnames';
2323
import {Group, RoomMember, User} from 'matrix-js-sdk';
@@ -137,25 +137,18 @@ function useIsEncrypted(cli, room) {
137137
}
138138

139139
function useHasCrossSigningKeys(cli, member, canVerify, setUpdating) {
140-
// use a ref to setUpdating because we don't want to rerun
141-
// the useAsyncMemo hook when it changes.
142-
const updatingRef = useRef();
143-
useEffect(() => {
144-
updatingRef.current = setUpdating;
145-
}, [setUpdating]);
146-
147140
return useAsyncMemo(async () => {
148141
if (!canVerify) {
149142
return false;
150143
}
151-
updatingRef.current(true);
144+
setUpdating(true);
152145
try {
153146
await cli.downloadKeys([member.userId]);
154147
const xsi = cli.getStoredCrossSigningForUser(member.userId);
155148
const key = xsi && xsi.getId();
156149
return !!key;
157150
} finally {
158-
updatingRef.current(false);
151+
setUpdating(false);
159152
}
160153
}, [cli, member, canVerify], false);
161154
}
@@ -1356,9 +1349,9 @@ const BasicUserInfo = ({room, member, groupId, devices, isRoomEncrypted}) => {
13561349
homeserverSupportsCrossSigning &&
13571350
isRoomEncrypted && !userVerified && !isMe;
13581351

1359-
const setUpdating = useCallback((updating) => {
1360-
setPendingUpdateCount(pendingUpdateCount + (updating ? 1 : -1));
1361-
}, [setPendingUpdateCount, pendingUpdateCount]);
1352+
const setUpdating = (updating) => {
1353+
setPendingUpdateCount(count => count + (updating ? 1 : -1));
1354+
};
13621355
const hasCrossSigningKeys =
13631356
useHasCrossSigningKeys(cli, member, canVerify, setUpdating );
13641357

0 commit comments

Comments
 (0)