Created
December 10, 2022 14:54
-
-
Save luigircruz/181d93a5673448e6a56d913d98708edf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react'; | |
| export default function useDeviceDetect() { | |
| const [isMobile, setMobile] = useState(false); | |
| useEffect(() => { | |
| const userAgent = typeof window.navigator === 'undefined' ? '' : navigator.userAgent; | |
| const mobile = Boolean(userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile|WPDesktop/i)); | |
| setMobile(mobile); | |
| }, []); | |
| return { isMobile }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment