import { useEffect, useState } from 'react' /** Chrome / Edge / Android "install app" prompt, when the browser offers one. * Returns a function that shows it, or null. (iOS: Share → Add to Home Screen.) */ export function useInstallPrompt() { const [event, setEvent] = useState(null) useEffect(() => { const onPrompt = (e) => { e.preventDefault() setEvent(e) } const onInstalled = () => setEvent(null) window.addEventListener('beforeinstallprompt', onPrompt) window.addEventListener('appinstalled', onInstalled) return () => { window.removeEventListener('beforeinstallprompt', onPrompt) window.removeEventListener('appinstalled', onInstalled) } }, []) if (!event) return null return async () => { event.prompt() await event.userChoice setEvent(null) } }