갈푸라떼
갈푸라떼는 개발중
갈푸라떼
전체 방문자
오늘
어제
  • 분류 전체보기 (232)
    • CS (0)
      • CSinfo (0)
    • Frontend (15)
      • HTML,CSS (1)
      • Javascript (2)
      • React (0)
      • React Hook (12)
    • Backend (0)
      • Python (0)
      • Node.js (0)
      • php (0)
    • DB (2)
      • MySQL (2)
      • BigQuery (0)
      • Mongodb (0)
    • Study (186)
      • JavaScript (72)
      • JavaScript(Clean code) (50)
      • Node.js (11)
      • HTML,CSS (13)
      • React (30)
      • TypeScript (10)
      • React-Native (0)
    • Error (2)
      • error (2)
    • Git (22)
      • Git (22)
    • Help Coding (4)
      • Useful websites (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • Github

공지사항

인기 글

태그

  • 자바스크립트엔진
  • PM2
  • Babel
  • SPREAD
  • 상속
  • symbol
  • 스코프 체인
  • 오버라이딩
  • function
  • 호이스팅
  • 싱글스레드
  • prototype
  • 원시타입
  • structure
  • 함수
  • 렉시컬 환경
  • 정적 레벨
  • 이터러블
  • 네이밍
  • 심볼
  • 프로토타입
  • ECMAScript
  • class
  • 실행 컨텍스트
  • Arrow
  • 인터프리터
  • 컴파일러
  • 객체타입
  • nodemon
  • this

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
갈푸라떼

갈푸라떼는 개발중

Frontend/React Hook

[React-Hooks] React Hooks - useNotification

2022. 7. 14. 00:12

* useNotification

  • useNotification는 알림이 실행되는 hook이다.
  • Notification에 대한 정보는 https://developer.mozilla.org/ko/docs/Web/API/notification 해당 링크를 참조
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("check", { body: "body" });
  return (
    <div>
      <button onClick={triggerNotif}>Click</button>
    </div>
  );
};

export default App;

'Frontend > React Hook' 카테고리의 다른 글

[React-Hooks] React Hooks - useAxios  (0) 2022.07.14
[React-Hooks] React Hooks - useFullscreen  (0) 2022.07.13
[React-Hooks] React Hooks - useScroll  (0) 2022.07.13
[React-Hooks] React Hooks - useFadeIn & useNetwork  (0) 2022.07.13
[React-Hooks] React Hooks - useBeforeLeave  (0) 2022.07.13
    'Frontend/React Hook' 카테고리의 다른 글
    • [React-Hooks] React Hooks - useAxios
    • [React-Hooks] React Hooks - useFullscreen
    • [React-Hooks] React Hooks - useScroll
    • [React-Hooks] React Hooks - useFadeIn & useNetwork
    갈푸라떼
    갈푸라떼

    티스토리툴바