코드
import React, {useState, useRef, useEffect} from 'react'
function useNotification(title, options) {
if(!("Notification" in window)) {
return;
}
function fireNotif() {
if(Notification.permission !== 'granted') {
Notification.requestPermission().then(permission => {
if(permission === 'granted') {
new Notification(title, options);
} else {
return;
}})
}}
return fireNotif;
}
export default function App() {
const triggerNotif = useNotification('can I steal?', {body: 'nononono'});
return (
<div>
<button onClick={triggerNotif}>Hello</button>
</div>
)
}
배운점