Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

chore: add use-mobile hook for responsive sidebar breakpoint detection

valzor57a1e52d6c8a
diff --git a/frontend/src/hooks/use-mobile.js b/frontend/src/hooks/use-mobile.js
new file mode 100644
index 0000000..9c47a0d
--- /dev/null
+++ b/frontend/src/hooks/use-mobile.js
@@ -0,0 +1,19 @@
+import * as React from "react"
+
+const MOBILE_BREAKPOINT = 768
+
+export function useIsMobile() {
+ const [isMobile, setIsMobile] = React.useState(undefined)
+
+ React.useEffect(() => {
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
+ const onChange = () => {
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ }
+ mql.addEventListener("change", onChange)
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ return () => mql.removeEventListener("change", onChange);
+ }, [])
+
+ return !!isMobile
+}