mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix react-toastify with setTimeout
This commit is contained in:
+20
-12
@@ -3,20 +3,28 @@ import { toast } from "react-toastify";
|
||||
|
||||
const useError = (message) => {
|
||||
useEffect(() => {
|
||||
if (message) {
|
||||
const toastId = toast.error(message.toString(), {
|
||||
position: "top-right",
|
||||
autoClose: false,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: false,
|
||||
pauseOnHover: true,
|
||||
draggable: false,
|
||||
progress: undefined,
|
||||
theme: "dark",
|
||||
});
|
||||
if (message && message.length > 0) {
|
||||
const showErrorToast = () => {
|
||||
const toastId = toast.error(message.toString(), {
|
||||
position: "top-right",
|
||||
autoClose: false,
|
||||
hideProgressBar: true,
|
||||
closeOnClick: false,
|
||||
pauseOnHover: false,
|
||||
draggable: false,
|
||||
progress: undefined,
|
||||
theme: "dark",
|
||||
});
|
||||
|
||||
return () => {
|
||||
toast.dismiss(toastId);
|
||||
};
|
||||
};
|
||||
|
||||
const timeoutId = setTimeout(showErrorToast, 500);
|
||||
|
||||
return () => {
|
||||
toast.dismiss(toastId);
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}
|
||||
}, [message]);
|
||||
|
||||
+20
-12
@@ -3,20 +3,28 @@ import { toast } from "react-toastify";
|
||||
|
||||
const useSuccess = (message) => {
|
||||
useEffect(() => {
|
||||
if (message) {
|
||||
const toastId = toast.success(message.toString(), {
|
||||
position: "top-right",
|
||||
autoClose: 3000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: false,
|
||||
pauseOnHover: false,
|
||||
draggable: false,
|
||||
progress: undefined,
|
||||
theme: "dark",
|
||||
});
|
||||
if (message && message.length > 0) {
|
||||
const showSuccessToast = () => {
|
||||
const toastId = toast.success(message.toString(), {
|
||||
position: "top-right",
|
||||
autoClose: 3000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: false,
|
||||
pauseOnHover: false,
|
||||
draggable: false,
|
||||
progress: undefined,
|
||||
theme: "dark",
|
||||
});
|
||||
|
||||
return () => {
|
||||
toast.dismiss(toastId);
|
||||
};
|
||||
};
|
||||
|
||||
const timeoutId = setTimeout(showSuccessToast, 500);
|
||||
|
||||
return () => {
|
||||
toast.dismiss(toastId);
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}
|
||||
}, [message]);
|
||||
|
||||
Reference in New Issue
Block a user