mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
24 lines
522 B
JavaScript
24 lines
522 B
JavaScript
import React from 'react';
|
|
|
|
export default function useToast() {
|
|
const [toasts, setToasts] = React.useState([]);
|
|
|
|
const showToast = ({ message, delay, color, backgroundColor, title }) => {
|
|
const toast = {
|
|
id: toasts.length,
|
|
message,
|
|
delay,
|
|
backgroundColor,
|
|
color,
|
|
title,
|
|
};
|
|
setToasts([...toasts, toast].reverse());
|
|
};
|
|
|
|
const onToastFinished = (id) => {
|
|
setToasts(toasts.filter((toast) => toast.id !== id));
|
|
};
|
|
|
|
return [showToast, onToastFinished, toasts];
|
|
}
|