Created
November 30, 2020 21:35
-
-
Save kellenmace/81595565efd74bbb2010cd0017aa7464 to your computer and use it in GitHub Desktop.
Use React.lazy() to lazily load NPM packages on the client
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, { 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