Design-loving front-end engineer
Ryong
Design-loving front-end engineer
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
    • Framework
    • React
      • Concept
      • Library
      • Hook
      • Component
      • Test
    • NodeJS
    • Android
      • Concept
      • Code
      • Sunflower
      • Etc
    • Flutter
      • Concept
      • Package
    • Web
    • Web
    • CSS
    • Language
    • JavaScript
    • TypeScript
    • Kotlin
    • Dart
    • Algorithm
    • Data Structure
    • Programmers
    • Management
    • Git
    • Editor
    • VSCode
    • Knowledge
    • Voice
Design-loving front-end engineer

Ryong

React/Hook

[ Hook ] useNotification

2022. 8. 10. 11:01

๐Ÿ”ด  Introduction

โšช  Window Notification์— ๋Œ€ํ•œ ์˜ต์…˜์„ ์„ค์ •ํ•˜๋ฉด ๊ถŒํ•œ ํ—ˆ์šฉ ์—ฌ๋ถ€ ์ดํ›„ Notification์„ ๋„์›Œ์ฃผ๋Š” Hook

 

๐ŸŸ   Hook

 
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;
};

 

๐ŸŸก  Usage

 
import { useNotification } from "./hooks/useNotification";

function App() {
    const triggerNotif = useNotification("Notification Title", {
        body: "Notification Body",
    });
    return (
        <div className="App">
            <button onClick={triggerNotif}>Hello</button>
        </div>
    );
}

export default App;

 

์ €์ž‘์žํ‘œ์‹œ (์ƒˆ์ฐฝ์—ด๋ฆผ)

'React > Hook' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ Hook ] useScroll  (0) 2022.08.10
[ Hook ] usePreventLeave  (0) 2022.08.10
[ Hook ] useHover  (0) 2022.08.10
[ Hook ] useConfirm  (0) 2022.08.10
[ Hook ] useBeforeLeave  (0) 2022.08.10
    'React/Hook' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [ Hook ] useScroll
    • [ Hook ] usePreventLeave
    • [ Hook ] useHover
    • [ Hook ] useConfirm
    Design-loving front-end engineer
    Design-loving front-end engineer
    ๋””์ž์ธ์— ๊ด€์‹ฌ์ด ๋งŽ์€ ๋ชจ๋ฐ”์ผ ์•ฑ ์—”์ง€๋‹ˆ์–ด Ryong์ž…๋‹ˆ๋‹ค.

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”