Javascript/React

react-alert 대신 react-toastify 사용해서 알림 표시해보기

2023. 10. 5. 23:46
목차
  1. react-toasty 쓰는 이유
  2. react-toasty 설치 및 적용
  3. 참조 및 인용

react-alert 대신 react-toastify 사용해서 알림 표시해 보기


 

 

 

이번 글을 통해 배워갈 내용

  1. kimc가 react-alert 대신 react-toasty를 사용하는 이유
  2. react-toasty 적용해 보기

 


 

react-toasty 쓰는 이유

react-alert의 경우 리액트 18 버전이상에서 설치하는 경우

아래와 같은 에러가 발생합니다

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: solesesteluquis@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.1 || ^17" from react-alert@7.0.3
npm ERR! node_modules/react-alert
npm ERR! react-alert@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

 

해결하는 방법은

2023-10-05 기준 fork 되지 않은 npm을 설치해서 사용하는 것이지만

지속적으로 업데이트되지 않는 모듈을 쓰기보다는

자주 업데이트 되는 모듈을 사용하기로 하였습니다

https://www.npmjs.com/package/@blaumaus/react-alert

 

@blaumaus/react-alert

A simple react alert component. Latest version: 7.0.5, last published: a year ago. Start using @blaumaus/react-alert in your project by running `npm i @blaumaus/react-alert`. There are no other projects in the npm registry using @blaumaus/react-alert.

www.npmjs.com

 

react toasty는

공식문서에 따르면 아래와 같은 장점이 있습니다

 

    실제 설정이 쉽고, 10초 미만으로 작동시킬 수 있어요!
    매우 쉽게 사용자 정의할 수 있어요.
    RTL(우측에서 좌측으로) 지원
    닫기 위해 스와이프 가능 👌
    스와이프 방향 선택 가능
    선택한 애니메이션 쉽게 사용할 수 있어요. 예를 들어, animate.css와 잘 작동해요.
    토스트 내부에 리액트 컴포넌트를 표시할 수 있어요!
    onOpen 및 onClose 훅 있어요. 둘 다 토스트 내부에서 렌더링 된 리액트 컴포넌트에 전달된 속성에 접근 가능해요.
    프로그래밍 방식으로 토스트를 제거할 수 있어요.
    토스트별로 동작 정의 가능해요.
    창이 포커스를 잃을 때 토스트 일시 중지 가능 👁
    남은 시간을 표시하는 멋진 진행 막대기 있어요.
    토스트 업데이트 가능해요.
    진행 막대기를 NProgress와 유사하게 제어할 수 있어요 😲
    동시에 표시되는 토스트 개수 제한 가능
    다크 모드 지원 🌒
    그리고 더 많은 기능이 있어요!

 

 

react-toasty 설치 및 적용

npm 또는 yarn을 이용해서 설치합니다

$ npm install --save react-toastify
$ yarn add react-toastify

App.tsx 혹은 main.tsx Root인 컴포넌트에 아래와 같이 세팅해 줍니다

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import './index.css';
import { Provider } from 'react-redux';
import { store } from './store/index.ts';
import { ToastContainer } from 'react-toastify';

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <Provider store={store}>
      <App />
    </Provider>
    <ToastContainer />
  </React.StrictMode>,
);

그리고 사용하고자 하는 컴포넌트에 사용해 주면 됩니다

  import React from 'react';

  import { toast } from 'react-toastify';
  import 'react-toastify/dist/ReactToastify.css';
  
  function MyButton(){
    const notify = () => toast("매우 쉬워요!");

    return (
      <div>
        <button onClick={notify}>Notify!</button>
      </div>
    );
  }

 

 

https://fkhadra.github.io/react-toastify/introduction

 

 

참조 및 인용

https://github.com/fkhadra/react-toastify

 

GitHub - fkhadra/react-toastify: React notification made easy 🚀 !

React notification made easy 🚀 ! Contribute to fkhadra/react-toastify development by creating an account on GitHub.

github.com

https://fkhadra.github.io/react-toastify/introduction

 

React-toastify | React-Toastify

[![Financial Contributors on Open Collective](https://opencollective.com/react-toastify/all/badge.svg?label=financial+contributors)](https://opencollective.com/react-toastify) ![Travis (.org)](https://img.shields.io/travis/fkhadra/react-toastify.svg?label=

fkhadra.github.io

 


 

728x90

'Javascript > React' 카테고리의 다른 글

Vite 리액트 카카오맵 다음 주소 조회 API 연동 및 컴포넌트 개발(TS)  (0) 2024.04.01
React에 Redux Toolkit 사용해보기 Typescript Vite  (0) 2023.10.05
React에 카카오 지도 넣는 방법 (초간단) (Client Side Render)  (0) 2023.06.18
React로 이미지 업로드 및 필터 적용하고 출력해보기  (1) 2022.11.19
TypeScript와 함께 useReducer를 사용하는 방법  (0) 2022.07.16
  1. react-toasty 쓰는 이유
  2. react-toasty 설치 및 적용
  3. 참조 및 인용
'Javascript/React' 카테고리의 다른 글
  • Vite 리액트 카카오맵 다음 주소 조회 API 연동 및 컴포넌트 개발(TS)
  • React에 Redux Toolkit 사용해보기 Typescript Vite
  • React에 카카오 지도 넣는 방법 (초간단) (Client Side Render)
  • React로 이미지 업로드 및 필터 적용하고 출력해보기
kimc
kimc
coding, it, java, c, cpp, algorithm, javascript, frontend, backend
kimc
김씨의 코딩 스토리
kimc
전체
오늘
어제
  • 분류 전체보기 (718)
    • DB (9)
    • DevOps (55)
      • Linux (22)
      • Window (5)
      • Docker (9)
      • Kubernetes (19)
    • Spring (22)
    • Kotlin (77)
      • Kotlin 이론 (5)
      • Kotlin 알고리즘 (70)
      • Kotlin 기타 (2)
    • Java (283)
      • Java 이론 (1)
      • Java 알고리즘 (262)
      • Java 기타 (20)
    • Python (3)
      • Python 이론 (2)
      • Python 알고리즘 (0)
      • Python 기타 (1)
    • Javascript (52)
      • Javascript 이론 (0)
      • Javascript 알고리즘 (0)
      • Javascript 기타 (7)
      • 웹 기타 (15)
      • React (24)
      • NextJs (5)
      • TypeScript (1)
    • Go (9)
      • Go 이론 (2)
      • Go 알고리즘 (7)
      • Go 기타 (0)
    • C++ (106)
      • C++ 이론 (1)
      • C++ 알고리즘 (81)
      • C++ 기타 (19)
      • MFC (5)
    • Unreal (2)
    • Christian (71)
      • Prayer (67)
      • Testimony (4)
    • 김씨의 일상 (0)
    • 김씨의 생각 (2)
    • 기타 (26)
      • 프로그래밍 기타 (13)
      • 책 리뷰 (0)
      • 회복 (1)
      • 자격증 (5)
      • 프로모션 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • go
  • Java
  • 사칙연산
  • 자바
  • Kotlin
  • 티스토리챌린지
  • 오늘의 기도
  • DP
  • azure
  • map
  • 백준
  • 문자열
  • c++
  • 알고리즘
  • 자료구조
  • 수학
  • 오블완
  • 정렬
  • 구현
  • React

최근 댓글

최근 글

hELLO · Designed By 정상우.
kimc
react-alert 대신 react-toastify 사용해서 알림 표시해보기
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.