Make React compiler happy about some frankly non-issues

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2024-12-05 12:59:53 +00:00
parent b597abf567
commit 72f155640d
No known key found for this signature in database
GPG key ID: A2B008A5F49F5D0D
3 changed files with 26 additions and 32 deletions

View file

@ -27,7 +27,7 @@ type Props = {
const MATCH_SYSTEM_THEME_ID = "MATCH_SYSTEM_THEME_ID";
const QuickThemeSwitcher: React.FC<Props> = ({ requestClose }) => {
const orderedThemes = useMemo(getOrderedThemes, []);
const orderedThemes = useMemo(() => getOrderedThemes(), []);
const themeState = useTheme();
const nonHighContrast = findNonHighContrastTheme(themeState.theme);

View file

@ -6,7 +6,7 @@
* Please see LICENSE files in the repository root for full details.
*/
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { ClientEvent, MatrixClient, MatrixEventEvent, Room } from "matrix-js-sdk/src/matrix";
import { throttle } from "lodash";
@ -42,14 +42,12 @@ export function useUnreadThreadRooms(forceComputation: boolean): Result {
setResult(computeUnreadThreadRooms(mxClient, msc3946ProcessDynamicPredecessor, settingTACOnlyNotifs));
}, [mxClient, msc3946ProcessDynamicPredecessor, settingTACOnlyNotifs]);
// The exhautive deps lint rule can't compute dependencies here since it's not a plain inline func.
// We make this as simple as possible so its only dep is doUpdate itself.
// eslint-disable-next-line react-hooks/exhaustive-deps
const scheduleUpdate = useCallback(
throttle(doUpdate, MIN_UPDATE_INTERVAL_MS, {
leading: false,
trailing: true,
}),
const scheduleUpdate = useMemo(
() =>
throttle(doUpdate, MIN_UPDATE_INTERVAL_MS, {
leading: false,
trailing: true,
}),
[doUpdate],
);

View file

@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import { useEffect, useState } from "react";
import { useEffect, useMemo } from "react";
import type { Map as MapLibreMap } from "maplibre-gl";
import { createMap } from "./map";
@ -26,29 +26,25 @@ interface UseMapProps {
*/
export const useMap = ({ interactive, bodyId, onError }: UseMapProps): MapLibreMap | undefined => {
const cli = useMatrixClientContext();
const [map, setMap] = useState<MapLibreMap>();
useEffect(
() => {
try {
setMap(createMap(cli, !!interactive, bodyId, onError));
} catch (error) {
console.error("Error encountered in useMap", error);
if (error instanceof Error) {
onError?.(error);
}
const map = useMemo(() => {
try {
return createMap(cli, !!interactive, bodyId, onError);
} catch (error) {
console.error("Error encountered in useMap", error);
if (error instanceof Error) {
onError?.(error);
}
return () => {
if (map) {
map.remove();
setMap(undefined);
}
};
},
// map is excluded as a dependency
// eslint-disable-next-line react-hooks/exhaustive-deps
[interactive, bodyId, onError],
);
}
}, [bodyId, cli, interactive, onError]);
// cleanup
useEffect(() => {
if (!map) return;
return () => {
map.remove();
};
}, [map]);
return map;
};