
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
react-pwa-hazhtech
Advanced tools
A React library for Progressive Web App (PWA) functionality with install prompts and status tracking
The simplest way to add PWA install prompts and status tracking to your React app.
<PWAInstallButton /> anywhere, it handles everythingnpm install react-pwa-hazhtech
import { PWAProvider } from 'react-pwa-hazhtech';
function Root() {
return (
<PWAProvider>
<App />
</PWAProvider>
);
}
import { PWAInstallButton } from 'react-pwa-hazhtech';
function Navbar() {
return (
<nav>
<PWAInstallButton className="install-btn">
Add to Home Screen
</PWAInstallButton>
</nav>
);
}
PWAInstallButton renders null automatically when the app is already installed or the browser hasn't offered a prompt yet — no extra logic needed.
import { usePWA } from 'react-pwa-hazhtech';
function InstallBanner() {
const { isInstallable, isInstalled, isStandalone, promptInstall } = usePWA();
if (isInstalled || isStandalone) return <p>✓ App installed</p>;
if (!isInstallable) return null;
return (
<button onClick={promptInstall}>Install App</button>
);
}
<PWAProvider>Wrap your app root. Captures the browser install event and tracks PWA state.
<PWAProvider
onInstallPromptAvailable={(event) => console.log('Ready to install')}
onAppInstalled={() => console.log('Installed!')}
>
<App />
</PWAProvider>
| Prop | Type | Description |
|---|---|---|
onInstallPromptAvailable | (event: BeforeInstallPromptEvent) => void | Fires when the browser install prompt is ready |
onAppInstalled | () => void | Fires after the user installs the app |
<PWAInstallButton>A plug-and-play install button. Invisible when there's nothing to install.
<PWAInstallButton
className="my-btn"
style={{ color: 'white' }}
onInstall={(outcome) => console.log(outcome)} // 'accepted' | 'dismissed'
>
Install App
</PWAInstallButton>
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | "Install App" | Button label |
className | string | — | CSS class |
style | CSSProperties | — | Inline styles |
onInstall | (outcome: 'accepted' | 'dismissed') => void | — | Called after the prompt resolves |
usePWA()Access PWA state and actions anywhere inside <PWAProvider>. Throws a clear error if called outside the provider.
const {
isInstallable, // boolean — browser prompt is ready
isInstalled, // boolean — app has been installed
isStandalone, // boolean — running as installed PWA
promptInstall, // () => Promise<{outcome} | null>
installPromptEvent // BeforeInstallPromptEvent | null
} = usePWA();
Use these outside of React (e.g. in vanilla JS event handlers).
<PWAProvider> must be mounted for these to work.
import { triggerPWAInstall, isPWAInstallAvailable, isPWAMode } from 'react-pwa-hazhtech';
// Is the install prompt ready?
if (isPWAInstallAvailable()) { ... }
// Is the app running as an installed PWA?
if (isPWAMode()) { ... }
// Trigger install from anywhere
const result = await triggerPWAInstall();
if (result?.outcome === 'accepted') { ... }
Your app needs three things to be installable:
public/manifest.json{
"name": "My App",
"short_name": "MyApp",
"start_url": "/",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff",
"icons": [
{ "src": "icon-192x192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "icon-512x512.png", "sizes": "512x512", "type": "image/png" }
]
}
Link it in your HTML:
<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#000000">
public/sw.jsconst CACHE_NAME = 'my-app-v1';
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (e) => e.waitUntil(clients.claim()));
self.addEventListener('fetch', (e) => {
e.respondWith(caches.match(e.request).then(r => r || fetch(e.request)));
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
Serve your app over HTTPS (or
localhost) — browsers only fire the install prompt on secure origins.
| Browser | Minimum version |
|---|---|
| Chrome | 68+ |
| Edge | 79+ |
| Safari | 14.1+ (iOS 14.5+) |
| Firefox | 85+ (Android only) |
MIT © HazhTech
PRs are welcome! Open an issue if you find a bug or have a feature request.
If this library saved you time, consider buying me a coffee!
FAQs
A React library for Progressive Web App (PWA) functionality with install prompts and status tracking
The npm package react-pwa-hazhtech receives a total of 12 weekly downloads. As such, react-pwa-hazhtech popularity was classified as not popular.
We found that react-pwa-hazhtech demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.