Skip to content

Commit

Permalink
fix: mobile side bar auto collapsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ztjhz committed Apr 1, 2023
1 parent b868e71 commit fc95eec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';

import useStore from '@store/store';

import NewChat from './NewChat';
Expand All @@ -13,10 +14,16 @@ const Menu = () => {
const hideSideMenu = useStore((state) => state.hideSideMenu);
const setHideSideMenu = useStore((state) => state.setHideSideMenu);

const windowWidthRef = useRef<number>(window.innerWidth);

useEffect(() => {
if (window.innerWidth < 768) setHideSideMenu(true);
window.addEventListener('resize', () => {
if (window.innerWidth < 768) setHideSideMenu(true);
if (
windowWidthRef.current !== window.innerWidth &&
window.innerWidth < 768
)
setHideSideMenu(true);
});
}, []);

Expand Down

0 comments on commit fc95eec

Please sign in to comment.