so I am trying to get my toastify to only show up once five minutes before the time I have specified. I tried using the useEffect hook, but the toast still shows up every minute or so. The output I used to track if it the date works, and it does show me that they are indeed different minutes, but it still does show up at least one other time after I clicked on close for the first toast.
Are there other options than the useEffect hook for this or how can I improve my code in general?
export default function App() {
const [time, setTime] = useState(null);
const [showToast, setShowToast] = useState(false);
useEffect(() => {
const targetTime = new Date(2022, 11, 20, 11, 7);
const reminderTime = new Date(targetTime - 5 * 60000);
const currentTime = new Date();
const interval = setInterval(() => {
console.log(currentTime.getMinutes() + " " + reminderTime.getMinutes());
if (
currentTime.getHours() === reminderTime.getHours() &&
currentTime.getMinutes() === reminderTime.getMinutes()
) {
notify();
}
}, 60000);
setInterval(() => {
setTime(new Date());
}, 1000);
return () => {
clearInterval(interval);
};
}, []);
const notify = () =>
toast(customMsg, {
icon: <InfoOutlinedIcon />,
autoClose: false,
closeOnClick: false
});
const customMsg = () => (
<div>
Hello Toaster Test
<div>123</div>
</div>
);
return (
<div>
<div> {time ? time.toString() : "Loading"}</div>
<ToastContainer limit={1} />
</div>
);
}