react-pwa-install-prompt
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

react-pwa-install-prompt

A react hook to prompt the install of your PWA in supported browsers (Chrome desktop & mobile)

NPM JavaScript Style Guide

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.5
    164
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.5
    164
  • 1.0.4
    0
  • 1.0.3
    0
  • 1.0.2
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i react-pwa-install-prompt

Weekly Downloads

164

Version

1.0.5

License

MIT

Unpacked Size

18.6 kB

Total Files

9

Last publish

Collaborators

  • ericedouard