Skip to content

Commit

Permalink
feat: update mobile view
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Jan 31, 2023
1 parent c5e77d7 commit bc215ca
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions apps/storefront/src/hooks/useMobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ import {
const useMobile = () => {
const [isMobile, setIsMobile] = useState<boolean>(false)

const ua = navigator.userAgent.toLowerCase()
const agents = ['iphone', 'ipad', 'ipod', 'android', 'windows phone'] // All fields that may be mobile devices
// const ua = navigator.userAgent.toLowerCase()
// const agents = ['iphone', 'ipad', 'ipod', 'android', 'windows phone'] // All fields that may be mobile devices

useEffect(() => {
agents.forEach((item: string) => {
if (ua.indexOf(item) !== -1) {
setIsMobile(true)
}
})
// agents.forEach((item: string) => {
// if (ua.indexOf(item) !== -1) {
// setIsMobile(true)
// }
// })
const resize = () => {
setIsMobile(document.body.clientWidth <= 750)
}

resize()

window.addEventListener('resize', resize)

return () => {
window.removeEventListener('resize', resize)
}
}, [])

return [isMobile]
Expand Down

0 comments on commit bc215ca

Please sign in to comment.