Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Allow for programatic closing of toasts outside of the scope they are called #63

@mirshko

Description

@mirshko

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 });

    const thing = await doAsyncThing();

    /* 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions