Yet another library to display pwa installation prompt in a react application.
npm install react-prompt-pwa
Before using this library make sure your react application fulfils the criteria for an installable progressive web app.
It consists of two components - PwaPromptProvider component and usePwaPrompt hook.
Add provider in the root of your react application -
import { PwaPromptProvider } from "react-prompt-pwa";
function App() {
// app code
return (
<PwaPromptProvider>
{/* rest of the components */}
</PwaPromptProvider>
)
}Use the hook in some other component in the hierarchy -
import { usePwaPrompt } from "react-prompt-pwa";
function SomeComponent() {
const {supported, installed, install} = usePwaPrompt();
// component code
}Demo app url: https://demo-react-prompt-pwa.netlify.app/
Screenshots (manual instruction prompt)
| Android | iOS |
|---|---|
The usePwaPrompt hook returns an object with three properties -
supported: Whether the pwa installation is supported by the browser client.installed: Whether the react app is opened through installed PWA. Iftrueis passed to the optional boolean parameter, it instead checks whether PWA is present among the installed apps on the device (currently supports Android OS only). If you use the optional parameter, make sure to also definerelated_applicationsfield in theapp.webmanifestfile of your PWA (reference).install: Displays the PWA installation prompt when supported by the browser client. Returns a boolean promise indicating whether user has successfully installed the PWA.
Please note that not every browser supports PWA installation and some have different instructions for manual install. Please feel free to raise an issue or a PR if you want to add support for your desired browser ✌️.