Skip to content

Commit f4a7ef6

Browse files
committed
Fix open nav on mobile issue
1 parent c0d10ee commit f4a7ef6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/layouts/dashboard/layout.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useEffect, useState } from 'react';
1+
import { useCallback, useEffect, useState } from 'react';
2+
import { usePathname } from 'next/navigation';
23
import { styled } from '@mui/material/styles';
34
import { withAuthGuard } from 'src/hocs/with-auth-guard';
45
import { SideNav } from './side-nav';
56
import { TopNav } from './top-nav';
6-
import { usePathname } from 'next/navigation';
77

88
const SIDE_NAV_WIDTH = 280;
99

@@ -26,15 +26,23 @@ const LayoutContainer = styled('div')({
2626
export const Layout = withAuthGuard((props) => {
2727
const { children } = props;
2828
const pathname = usePathname();
29-
const [openNav, setOpenNav] = useState(true);
29+
const [openNav, setOpenNav] = useState(false);
3030

31-
useEffect(
31+
const handlePathnameChange = useCallback(
3232
() => {
3333
if (openNav) {
3434
setOpenNav(false);
3535
}
3636
},
37-
[pathname, openNav]
37+
[openNav]
38+
);
39+
40+
useEffect(
41+
() => {
42+
handlePathnameChange();
43+
},
44+
// eslint-disable-next-line react-hooks/exhaustive-deps
45+
[pathname]
3846
);
3947

4048
return (

0 commit comments

Comments
 (0)