설치

npm install notistack

 

예시 코드

src / app / layout.tsx
import ClientSnackbarProvider from "@/lib/ClientSnackbarProvider";


export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="ko">
      <body>
            <ClientSnackbarProvider />
            {children}
      </body>
    </html>
  );
}

 

src / lib / ClientSnackbarProvider.tsx
"use client";

import { enqueueSnackbar, SnackbarProvider } from "notistack";

const ClientSnackbarProvider = () => {
  return (
    <>
      <SnackbarProvider
        maxSnack={3} // 최대 누적 스택
        autoHideDuration={5000} // 지속시간
        // anchorOrigin={{ vertical: "bottom", horizontal: "left" }} // 스낵바 위치 지정
        // preventDuplicate={true} // 중복 메시지 표시 여부
        // hideIconVariant = {false} // 아이콘 숨김 여부
        // transitionDuration={{enter:300, exit:3000}} // 애니메이션 시간 변경 (ms)
      />
      <button onClick={() => enqueueSnackbar("스낵바 테스트 문구")}>기본 스낵바 추가</button>
      <button
        onClick={() =>
          enqueueSnackbar("스낵바 테스트 문구", {
            // 'default' | 'error' | 'warning' | 'info' | 'success'
            // variant: "default",
            variant: "info",
            // variant: "success",
            // variant: "warning",
            // variant: "error",
          })
        }
      >
        variant 지정 스낵바 추가
      </button>
    </>
  );
};

export default ClientSnackbarProvider;

 

 

https://github.com/iamhosseindhv/notistack?tab=readme-ov-file

 

GitHub - iamhosseindhv/notistack: Highly customizable notification snackbars (toasts) that can be stacked on top of each other

Highly customizable notification snackbars (toasts) that can be stacked on top of each other - iamhosseindhv/notistack

github.com

https://notistack.com/api-reference

 

Notistack: Show feedback to your users with a call of a function

Notistack is a React library which makes it super easy to display notifications on your web apps. It is highly customizable and allows you to stack snackbars/toasts on top of one another

notistack.com