Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created July 19, 2023 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DWboutin/7cf15061157f2daf04ef1e25dd110b6a to your computer and use it in GitHub Desktop.
Save DWboutin/7cf15061157f2daf04ef1e25dd110b6a to your computer and use it in GitHub Desktop.
Detect apple device in React.js
import { useEffect } from "react"
export function useDetectAppleDevice() {
const isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator.userAgent)
useEffect(() => {
if (isMac) {
document.documentElement.classList.add("apple-device")
}
}, [isMac])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment