Provides React toast notifications with action buttons, promise states, and custom JSX.
Downloads / mo 226.6M
Stars 13.2K
Last release 2.0.8
License MIT Strengths Includes action and cancel buttons . Attach primary and secondary actions directly to notifications. Supports headless custom content . Render unstyled custom JSX while retaining toast functionality. Limitations Actions close their toast . Call event.preventDefault() when an action should leave its toast visible. Headless content needs styling . Provide the visual styling when using the unstyled headless renderer. $ npm install react@18.3.1 react-dom@18.3.1 sonner@2.0.8 Copy
import { Toaster, toast } from 'sonner';
// ...
function App() {
return (
<div>
<Toaster />
<button onClick={() => toast('My first toast')}>Give me a toast</button>
</div>
);
}
Sonner examples From open-source projects on GitHub export function showToast(
message: string,
variant: ToastVariants,
options: number | ExternalToast = TOAST_VISIBLE_DURATION
) {
const _options: ExternalToast = typeof options === "number" ? { duration: options } : options;
if (!_options.duration) _options.duration = TOAST_VISIBLE_DURATION;
if (!_options.position) _options.position = "bottom-center";
const onClose = (toastId: string | number) => {
toast.dismiss(toastId);
};
const toastElements: { [x in ToastVariants]: (t: number | string) => JSX.Element } = {
success: (toastId) => <SuccessToast message={message} onClose={onClose} toastId={toastId} />,
error: (toastId) => <ErrorToast message={message} onClose={onClose} toastId={toastId} />,
warning: (toastId) => <WarningToast message={message} onClose={onClose} toastId={toastId} />,
};
return toast.custom(
toastElements[variant] ||
((toastId) => <SuccessToast message={message} onClose={onClose} toastId={toastId} />),
_options
);
}
Show full example Displays a succinct message temporarily.
Downloads / mo 168.4M
Stars 19.5K
Last release 1.3.1
License MIT $ npm install react@18.3.1 react-dom@18.3.1 @radix-ui/react-toast@1.3.1 Copy
import { Toast } from "radix-ui";
export default () => (
<Toast.Provider>
<Toast.Root>
<Toast.Description>Saved!</Toast.Description>
<Toast.Close>Dismiss</Toast.Close>
</Toast.Root>
<Toast.Viewport />
</Toast.Provider>
);
@radix-ui/react-toast examples From open-source projects on GitHub const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
return (
<ToastPrimitives.Root
ref={ref}
className={cn(toastVariants({ variant }), className)}
{...props}
/>
);
});
Show full example Provides headless React components and low-level hooks with full control over CSS and accessibility features.
Downloads / mo 109.8M
Stars 11.4K
Last release 1.9.0
License MIT $ npm install @base-ui/react@1.9.0 react@19.2.0 react-dom@19.2.0 Copy
"use client";
import { Toast } from "@base-ui/react/toast";
export default function App() {
return <Toast.Provider><Notifications /></Toast.Provider>;
}
function Notifications() {
const manager = Toast.useToastManager();
return (
<>
<button onClick={() => manager.add({ title: "Saved" })}>Notify</button>
<Toast.Portal>
<Toast.Viewport>
{manager.toasts.map((toast) => (
<Toast.Root key={toast.id} toast={toast}>
<Toast.Content><Toast.Title /><Toast.Close>Dismiss</Toast.Close></Toast.Content>
</Toast.Root>
))}
</Toast.Viewport>
</Toast.Portal>
</>
);
}
Displays React notifications with promise states, custom JSX, and headless rendering hooks.
Downloads / mo 19.7M
Stars 11.0K
Last release 2.6.1
License MIT Strengths Maps promises to notifications . Update loading notifications automatically when a promise succeeds or fails. Supports a headless renderer . Use the toaster hook to build a custom notification renderer. Limitations Dismissal preserves the exit animation . Use toast.remove when a notification must disappear immediately. Repeated events need stable identifiers . Provide a permanent identifier to prevent duplicate notifications of the same kind. $ npm install react@18.3.1 react-dom@18.3.1 react-hot-toast@2.6.1 Copy
import toast, { Toaster } from 'react-hot-toast';
const notify = () => toast('Here is your toast.');
const App = () => {
return (
<div>
<button onClick={notify}>Make me a toast</button>
<Toaster />
</div>
);
};
react-hot-toast examples From open-source projects on GitHub export function showToast(
message: string,
variant: ToastVariants,
// Options or duration (duration for backwards compatibility reasons)
options: number | ToastOptions = TOAST_VISIBLE_DURATION
) {
//
const _options: ToastOptions = typeof options === "number" ? { duration: options } : options;
if (!_options.duration) _options.duration = TOAST_VISIBLE_DURATION;
const onClose = (toastId: string) => {
toast.remove(toastId);
};
const toastElements: { [x in ToastVariants]: (t: Toast) => JSX.Element } = {
success: (t) => (
<SuccessToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />
),
error: (t) => <ErrorToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />,
warning: (t) => (
<WarningToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />
),
};
return toast.custom(
toastElements[variant] ||
((t) => <DefaultToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />),
_options
);
}
Show full example Displays React notifications with promise tracking, custom content, and update controls.
Downloads / mo 19.6M
Stars 13.4K
Last release 11.2.0
License MIT Strengths Tracks promise outcomes . Show pending, success, and error states through the promise helper. Updates existing notifications . Change toast content and options without creating a replacement notification. Limitations Updates retain previous options . Override inherited content and options explicitly when changing an existing toast. Updates skip transitions by default . Provide a transition or className when updated notifications should animate. $ npm install react@18.3.1 react-dom@18.3.1 react-toastify@11.2.0 Copy
import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
function App(){
const notify = () => toast("Wow so easy!");
return (
<div>
<button onClick={notify}>Notify!</button>
<ToastContainer />
</div>
);
}
React-Toastify examples From open-source projects on GitHub export const toastError = (
err: string | Error | Error[],
option: ToastOptions = toastErrorOption,
): void => {
const errs = toArrayIfNot(err);
if (errs.length === 0) {
return;
}
for (const err of errs) {
const message = typeof err === 'string' ? err : err.message;
toast.error(message, option);
}
};
Show full example Queues and stacks React snackbars through a provider and enqueue API.
Downloads / mo 10.5M
Stars 4.1K
Last release 3.0.2
License MIT Strengths Controls concurrent snackbar display . Configure the maximum number of snackbars displayed together. Supports custom snackbar variants . Map named variants to custom components with application-specific properties. Limitations Persistent snackbars can be evicted . The oldest persistent snackbar is removed when all display slots are occupied. Custom components own their actions . Render action controls inside custom components; the built-in action option does nothing. $ npm install react@18.3.1 react-dom@18.3.1 notistack@3.0.2 Copy
import { SnackbarProvider, enqueueSnackbar } from 'notistack';
const App = () => {
return (
<div>
<SnackbarProvider />
<button onClick={() => enqueueSnackbar('That was easy!')}>Show snackbar</button>
</div>
);
};
Notistack examples From open-source projects on GitHub function MyApp() {
const { enqueueSnackbar } = useSnackbar();
const handleClick = () => {
enqueueSnackbar('I love snacks.');
};
const handleClickVariant = (variant: VariantType) => () => {
// variant could be success, error, warning, info, or default
enqueueSnackbar('This is a success message!', { variant });
};
return (
<React.Fragment>
<Button onClick={handleClick}>Show snackbar</Button>
<Button onClick={handleClickVariant('success')}>Show success snackbar</Button>
</React.Fragment>
);
}
Show full example Provides responsive, accessible React UI components built with React and Emotion.
Downloads / mo 8.3M
Stars 40.7K
Last release 3.38.0
License MIT $ npm i @chakra-ui/react @emotion/react Copy
"use client";
import { Provider } from "@/components/ui/provider";
import { Toaster, toaster } from "@/components/ui/toaster";
export default function App() {
return (
<Provider>
<button onClick={() => toaster.create({ title: "Saved" })}>Notify</button>
<Toaster />
</Provider>
);
}
Chakra UI examples From open-source projects on GitHub export const Toaster = () => (
<Portal>
<ChakraToaster insetInline={{ mdDown: "4" }} toaster={toaster}>
{(toast) => (
<Toast.Root width={{ md: "sm" }}>
{toast.type === "loading" ? <Spinner color="brand.solid" size="sm" /> : <Toast.Indicator />}
<Stack flex="1" gap="1" maxWidth="100%">
{Boolean(toast.title) ? <Toast.Title>{toast.title}</Toast.Title> : undefined}
{Boolean(toast.description) ? (
<Toast.Description overflowWrap="break-word" wordBreak="break-word">
{toast.description}
</Toast.Description>
) : undefined}
</Stack>
{toast.action ? <Toast.ActionTrigger>{toast.action.label}</Toast.ActionTrigger> : undefined}
{Boolean(toast.meta?.closable) ? <Toast.CloseTrigger /> : undefined}
</Toast.Root>
)}
</ChakraToaster>
</Portal>
);
Show full example Adds React element support to sweetalert2 content.
Downloads / mo 450.3K
Stars 728
Last release 5.1.2
License MIT $ npm install react@18.3.1 react-dom@18.3.1 sweetalert2@11.26.25 sweetalert2-react-content@5.1.2 Copy
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
import "sweetalert2/dist/sweetalert2.min.css";
const ReactSwal = withReactContent(Swal);
export default function App() {
return (
<button onClick={() => ReactSwal.fire({ toast: true, position: "top-end", showConfirmButton: false, timer: 2000, title: <strong>Saved</strong> })}>
Show toast
</button>
);
}
sweetalert2-react-content examples From open-source projects on GitHub export async function openDirToast({ filePath, text, html, ...props }: SweetAlertOptions & { filePath: string }) {
const swal = text ? toast : ReactSwal;
// @ts-expect-error todo
const { value } = await swal.fire<string>({
...swalToastOptions,
showConfirmButton: true,
confirmButtonText: i18n.t('Show'),
showCancelButton: true,
cancelButtonText: i18n.t('Close'),
text,
html,
...props,
});
if (value) showItemInFolder(filePath);
}
Show full example