From cae0c1d6c094a1662e1e390962ed10b8eabe73ea Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 13 Jun 2024 20:39:21 +0800 Subject: [PATCH] perf: improve sidebar hide logic --- src/client/components/layout/Menu.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/components/layout/Menu.tsx b/src/client/components/layout/Menu.tsx index eef9eba..7731b96 100644 --- a/src/client/components/layout/Menu.tsx +++ b/src/client/components/layout/Menu.tsx @@ -3,14 +3,16 @@ import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; import { LuMenu } from 'react-icons/lu'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { useGlobalEventSubscribe } from '@/utils/event'; +import { useRouterState } from '@tanstack/react-router'; +import { useWatch } from '@/hooks/useWatch'; export const MobileLayoutMenu: React.FC<{ list?: React.ReactNode; }> = React.memo((props) => { const [open, setOpen] = useState(false); + const state = useRouterState(); - useGlobalEventSubscribe('commonListSelected', () => { + useWatch([state.location.href], () => { setOpen(false); });