Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created November 30, 2020 21:35
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 kellenmace/81595565efd74bbb2010cd0017aa7464 to your computer and use it in GitHub Desktop.
Save kellenmace/81595565efd74bbb2010cd0017aa7464 to your computer and use it in GitHub Desktop.
Use React.lazy() to lazily load NPM packages on the client
import React, { Suspense } from "react"
import hasMounted from "../hooks/useHasMounted"
const PWAPrompt = React.lazy(() => import("react-ios-pwa-prompt"))
function PWAInstallPrompt() {
if (!hasMounted) return null
const isMobileChrome = navigator.userAgent.includes("CriOS")
// Don't show the install prompt for Chrome on iOS, since it
// does not provide the "Add to Home Screen" option.
if (isMobileChrome) return null
return (
<Suspense fallback={null}>
<PWAPrompt
copyTitle="Hey, you! 👇🏼"
copyBody="Tired of always using this app in a browser? Here's how to add it to your home screen –"
copyShareButtonLabel="1) Press the 'Share' button below."
delay={500}
promptOnVisit={3}
timesToShow={6}
permanentlyHideOnDismiss={false}
/>
</Suspense>
)
}
export default PWAInstallPrompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment