Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created October 26, 2022 15:39
Show Gist options
  • Save polluterofminds/1a113308c6a47e58e4380f9c5687898d to your computer and use it in GitHub Desktop.
Save polluterofminds/1a113308c6a47e58e4380f9c5687898d to your computer and use it in GitHub Desktop.
App.js for progressive web app
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