perf: improve sidebar hide logic

This commit is contained in:
moonrailgun 2024-06-13 20:39:21 +08:00
parent 0deec1fc55
commit cae0c1d6c0

View File

@ -3,14 +3,16 @@ import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet';
import { LuMenu } from 'react-icons/lu'; import { LuMenu } from 'react-icons/lu';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { ScrollArea } from '@/components/ui/scroll-area'; 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<{ export const MobileLayoutMenu: React.FC<{
list?: React.ReactNode; list?: React.ReactNode;
}> = React.memo((props) => { }> = React.memo((props) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const state = useRouterState();
useGlobalEventSubscribe('commonListSelected', () => { useWatch([state.location.href], () => {
setOpen(false); setOpen(false);
}); });