Skip to content

Commit

Permalink
fix(header): dropdowns disappear on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Mar 22, 2022
1 parent f10a7a8 commit 52338fd
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/ui/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ const TopDropdownMenu = ({
mobileText,
text,
}) => {
const [width, setWidth] = React.useState(
typeof window !== 'undefined' && window.innerWidth,
);
const isMobile = width < 480;

React.useEffect(() => {
window.addEventListener('resize', () => {
setWidth(window.innerWidth);
});
return () => {
window.removeEventListener('resize', () => {
setWidth(window.innerWidth);
});
};
}, []);

const Component = ({ mobileText }) => (
<Dropdown
id={id}
Expand All @@ -52,14 +68,9 @@ const TopDropdownMenu = ({
<Dropdown.Menu role="group">{children}</Dropdown.Menu>
</Dropdown>
);
if (typeof window !== 'undefined') {
const resolution = window?.innerWidth;
const isMobile = resolution < 480;
return (
<>{isMobile ? <Component mobileText={mobileText} /> : <Component />}</>
);
}
return null;
return (
<>{isMobile ? <Component mobileText={mobileText} /> : <Component />}</>
);
};

const Main = ({
Expand Down

0 comments on commit 52338fd

Please sign in to comment.