react-pwa-install-prompt
v1.0.5
Published
A react hook to prompt the install of your PWA in supported browers (Chrome desktop & mobile)
Downloads
428
Readme
react-pwa-install-prompt
A react hook to prompt the install of your PWA in supported browsers (Chrome desktop & mobile)
Install
yarn add react-pwa-install-prompt
Usage
import React from 'react'
import usePWA from 'react-pwa-install-prompt'
const Example = () => {
const { isStandalone, isInstallPromptSupported, promptInstall } = usePWA()
const onClickInstall = async () => {
const didInstall = await promptInstall()
if (didInstall) {
// User accepted PWA install
}
}
const renderInstallButton = () => {
if (isInstallPromptSupported && isStandalone)
return (
<button onClick={onClickInstall}>Prompt PWA Install</button>
)
return null
}
return (<div>
<h2>PWA Infos</h2>
<p>Is Install Prompt Supported ? {isInstallPromptSupported ? 'true' : 'false'}</p>
<p>Is Standalone ? {isStandalone ? 'true' : 'false'}</p>
{renderInstallButton()}
</div>)
}
export default Example
License
MIT © eric-edouard