Skip to content

Commit

Permalink
Use hook for responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed Oct 23, 2024
1 parent 2296ca8 commit 0998dc0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"re-resizable": "^6.10.0",
"react": "18",
"react-dom": "18",
"react-responsive": "^10.0.0",
"recoil": "^0.7.7",
"tailwind-merge": "2.4.0",
"tailwindcss-animate": "1.0.7",
Expand Down
69 changes: 49 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions src/lib/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useCallback, useEffect } from "react";
import { useMediaQuery } from "react-responsive";

export const useScreenWidthWithResize = () => {
const [width, setWidth] = useState(0);
Expand All @@ -20,17 +21,8 @@ export const useScreenWidthWithResize = () => {
};

export const useIsMobile = () => {
const [isMobile, setIsMobile] = useState(false);
const handleResize = useCallback(() => {
// Use desktop breakpoint to allow for big screen mobiles
setIsMobile(window.innerWidth < 1024);
}, []);

useEffect(() => {
handleResize();
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);

return isMobile;
const isDesktopOrLaptop = useMediaQuery({
query: "(min-width: 1224px)",
});
return !isDesktopOrLaptop;
};

0 comments on commit 0998dc0

Please sign in to comment.