From 46e0bd3a67bacefc192bfd8e83eec1dc23a8b12d Mon Sep 17 00:00:00 2001 From: Adarsh Tiwari Date: Sat, 24 May 2025 01:10:50 +0530 Subject: [PATCH] simplify getLabelCount function logic --- apps/mail/components/ui/nav-main.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/mail/components/ui/nav-main.tsx b/apps/mail/components/ui/nav-main.tsx index 418796ef6..f6a6e888e 100644 --- a/apps/mail/components/ui/nav-main.tsx +++ b/apps/mail/components/ui/nav-main.tsx @@ -172,13 +172,9 @@ export function NavMain({ items }: NavMainProps) { [pathname, category, searchParams, isValidInternalUrl], ); - const getLabelCount = React.useMemo(() => { - if (!stats) return () => 0; - - return (labelName: string | undefined) => { - if (!labelName) return 0; - return stats.find((stat) => stat.label?.toLowerCase() === labelName.toLowerCase())?.count ?? 0; - }; + const getLabelCount = useCallback((labelName: string | undefined): number => { + if (!stats || !labelName) return 0; + return stats.find((stat) => stat.label?.toLowerCase() === labelName.toLowerCase())?.count ?? 0; }, [stats]); const activeAccount = React.useMemo(() => {