-
Notifications
You must be signed in to change notification settings - Fork 9
/
A2H.jsx
35 lines (30 loc) · 833 Bytes
/
A2H.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { h } from 'preact';
import './A2H.css';
import { useEffect, useState } from 'preact/hooks';
const A2H = () => {
const [prompt, setPrompt] = useState(false);
useEffect(() => {
// this will catch the beforeinstallprompt and prevents the native prompt from appearing
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault();
setPrompt(e);
});
}, []);
if (!prompt) {
return '';
}
return (
<button
className="text-white bg-indigo-800 hover:bg-indigo-700 rounded-full shadow a2h"
onClick={() => prompt.prompt() /* fire the prompt on button click */}
>
<svg viewBox="0 0 24 24">
<path
fill="currentColor"
d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"
/>
</svg>
</button>
);
};
export default A2H;