react-use-pwa-install
Version:
Custom React hook for PWA install button.
39 lines (25 loc) • 1.13 kB
Markdown
# react-use-pwa-install [](https://www.npmjs.com/package/react-use-pwa-install) 
Custom React hook for PWA install button.
## Installation
```bash
npm install react-use-pwa-install
```
## How to use
```jsx
import { usePWAInstall } from 'react-use-pwa-install'
export const Header = () => {
const install = usePWAInstall()
return (
<header>
<h1>My app</h1>
{install && <button onClick={install}>Install</button>}
</header>
)
}
```
### Screencast

### Demo
Check [website](https://react-use-pwa-install-demo.glitch.me/) or [code](https://glitch.com/edit/#!/react-use-pwa-install-demo).
## Note
Don't forget to fulfill PWA requirements ([web.dev](https://web.dev/install-criteria/), [mdn](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Installable_PWAs)) otherwise the `usePWAInstall` will return `null`. Same goes for already installed app.