You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
I've noticed if youre using toasts to show multiple states inside a try catch block and at a point down the line if the code catches any toasts created (with a hideAfter set to 0, for programatic closing) there seems to be no way to close them from the catch block.
Example
(async()=>{try{const{ hide }=cogoToast.loading("Loading...",{hideAfter: 0});constthing=awaitdoAsyncThing();/* Can't be called from the catch block. */hide();cogoToast.success("Completed Action");}catch(err){cogoToast.error(err.message);}})();
It would be great to be able to have a second function exposed by the lib that would accept a toastId to programmatically close it, with the ability to set an id on the toast options.
I realize this might expand the complexity of the library though.
The text was updated successfully, but these errors were encountered:
I'm having the same problem.
I found a solution like this. document.getElementById("ct-container").style.display = "none";
But, cogoToast.destroy()
function is necessary in my opinion.
Hey @sedatkimya I found a workaround that’s prob a bit better than that option and also doesn’t touch the DOM directly.
(async()=>{/* Empty function so the catch block doesn’t error out. Prob a better way of doing this. */lethideToast=()=>{};try{const{ hide }=cogoToast.loading("Loading...",{hideAfter: 0});hideToast=hide;constthing=awaitdoAsyncThing();/* Can't be called from the catch block. */hide();cogoToast.success("Completed Action");}catch(err){hideToast();cogoToast.error(err.message);}})();
This handles well if the doAsyncThing function fails the loading toast can be dismissed.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I've noticed if youre using toasts to show multiple states inside a try catch block and at a point down the line if the code catches any toasts created (with a hideAfter set to 0, for programatic closing) there seems to be no way to close them from the catch block.
Example
It would be great to be able to have a second function exposed by the lib that would accept a toastId to programmatically close it, with the ability to set an id on the toast options.
I realize this might expand the complexity of the library though.
The text was updated successfully, but these errors were encountered: