我想在关闭模态后使用react toast ify显示一个成功消息弹出窗口,但它不起作用。也许是因为我在关闭模态时使用动画来稍微延迟。我可以做一些事情,比如使用超时,然后运行setIModalOpen(false(,这样弹出消息就可以在关闭模态之前显示。
模态组件
const onFormSubmitHandler=(e)=>{
e.preventDefault();
if(!inputRef.current.value)
return;
//callback from parent component
updateUnavailableTimeSlotsInDb(inputRef.current.value, date,`${date} ${selectedTimeSlot}:00`);
toast.success(`Booked for ${reasonStr} on ${selectedDate} at time ${selectedTimeSlot}:00`, {
position: "top-center",
autoClose: 2000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});
inputRef.current.value='';
setIsModalOpen(false);
}
Parent(尝试在父组件的回调中调用toast.success,但也不起作用(
const updateUnavailableTimeSlotsInDb=(reasonStr,selectedDate,selectedTimeSlot)=>{
//popup with confirmation message
/*toast.success(`Booked for ${reasonStr} on ${selectedDate} at time ${selectedTimeSlot}:00`, {
position: "top-center",
autoClose: 2000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});*/
//add selectedTimeSlot to database. timeSlot will no longer be
available
unavailableTimeSlotsMutation.mutate({
[selectedTimeSlot]:true
})
编辑:我没有使用ToastContainer只是发现了
我没有使用ToastContainer,只是发现了