import { useEffect, useRef, useState } from 'react'; import { BeforeInstallPromptEvent } from '../../global'; import { useAnalytics } from '../../Hooks/useAnalytics'; export const InstallPWAButton = () => { const supportsPWARef = useRef(false); const [promptInstall, setPromptInstall] = useState(null); const analytics = useAnalytics(); const handler = (e: BeforeInstallPromptEvent) => { e.preventDefault(); supportsPWARef.current = true; setPromptInstall(e); }; useEffect(() => { window.addEventListener('beforeinstallprompt', handler); return () => window.removeEventListener('transitionend', handler); }, []); if (!supportsPWARef.current) { return null; } return ( ); };