Hook
useInstallPrompt
useInstallPrompt normalizes install availability, user choice, installed state, and prompt failures without showing browser UI until your own user-initiated action calls prompt().
Preview
Live install capability
Status
Can prompt
Installed
The browser controls whether an install prompt becomes available.
Installation
pnpm dlx shadcn@latest add https://pwaui.com/r/use-install-prompt.jsonUsage
"use client"
import { useInstallPrompt } from "@/hooks/use-install-prompt"
export function InstallButton() { const { status, canPrompt, prompt } = useInstallPrompt()
if (!canPrompt && status !== "prompting") return null
return ( <button disabled={status === "prompting"} onClick={() => void prompt()}> {status === "prompting" ? "Opening…" : "Install app"} </button> )}Returns
status- The install lifecycle from unknown or unavailable through prompting and user choice.
canPrompt- Whether a captured browser prompt is currently available.
isInstalled- Whether the app is running installed or the appinstalled event has confirmed installation.
error- The most recent native prompt failure, if one occurred.
prompt()- Shows the captured browser prompt once and resolves with its outcome.
Behavior notes
- Mount the hook near the application root so it can capture the browser event when it fires.
- prompt() returns unavailable when no prompt has been captured and shares one in-flight request across repeated calls.
- Browsers that do not expose beforeinstallprompt remain unavailable; provide separate platform instructions when your product needs them.