From 2428fea9864735ff9bc5186bb1d95c9924e7b88a Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sat, 18 Mar 2023 19:48:56 +0800 Subject: [PATCH] Fix: meanDelay may be zero --- src/containers/Proxies/components/Proxy/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/containers/Proxies/components/Proxy/index.tsx b/src/containers/Proxies/components/Proxy/index.tsx index 7d7ba8f..7f11bde 100644 --- a/src/containers/Proxies/components/Proxy/index.tsx +++ b/src/containers/Proxies/components/Proxy/index.tsx @@ -53,7 +53,7 @@ export function Proxy (props: ProxyProps) { const meanDelay = config.history?.length ? config.history.slice(-1)[0].meanDelay : undefined const delayText = delay === 0 ? '-' : `${delay}ms` - const meanDelayText = meanDelay === undefined || meanDelay === 0 ? '' : `(${meanDelay}ms)` + const meanDelayText = !meanDelay ? '' : `(${meanDelay}ms)` useLayoutEffect(() => { const handler = () => { speedTest() } @@ -64,7 +64,8 @@ export function Proxy (props: ProxyProps) { const hasError = useMemo(() => delay === 0, [delay]) const color = useMemo( () => Object.keys(TagColors).find( - threshold => (meanDelay ?? delay) <= TagColors[threshold as keyof typeof TagColors], + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + threshold => (meanDelay || delay) <= TagColors[threshold as keyof typeof TagColors], ), [delay, meanDelay], )