export const useNotification = (title, options) => {
if (!("Notification" in window)) {
return;
}
const fireNotif = () => {
if (Notification.permission !== "granted") {
Notification.requestPermission().then(permission => {
if (permission === "granted") {
new Notification(title, options);
} else {
return;
}
});
} else {
new Notification(title, options);
}
};
return fireNotif;
};
const App = () => {
const triggerNotif = useNotification("Click Button", {
body: "Click me again!"
});
return (
<div className="App" style={{height: "70vw" }}>
<button onClick={triggerNotif}>Hello!</button>
</div>
);
};