Created
October 26, 2022 15:39
-
-
Save polluterofminds/1a113308c6a47e58e4380f9c5687898d to your computer and use it in GitHub Desktop.
App.js for progressive web app
This file contains 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 React, { useEffect, useState } from "react"; | |
import "./App.css"; | |
import MobileView from "./components/MobileView"; | |
import DesktopView from "./components/DesktopView"; | |
function App() { | |
const [mobile, setMobile] = useState(true); | |
useEffect(() => { | |
const isMobile = () => | |
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( | |
navigator.userAgent | |
); | |
setMobile(isMobile()); | |
}, []); | |
if (mobile) { | |
return <MobileView />; | |
} else { | |
return <DesktopView />; | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment