Skip to content

Commit

Permalink
Close custom toasts (#218)
Browse files Browse the repository at this point in the history
* Close custom toasts

* Remove hero updates
  • Loading branch information
emilkowalski authored Nov 5, 2023
1 parent c1e0ef6 commit 8a17c96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Observer {
message?: string | React.ReactNode;
type?: ToastTypes;
promise?: PromiseT;
jsx?: React.ReactElement;
},
) => {
const { message, ...rest } = data;
Expand Down Expand Up @@ -149,10 +150,9 @@ class Observer {
return id;
};

// We can't provide the toast we just created as a prop as we didn't create it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?
custom = (jsx: (id: number | string) => React.ReactElement, data?: ExternalToast) => {
const id = data?.id || toastsCounter++;
this.publish({ jsx: jsx(id), id, ...data });
this.create({ jsx: jsx(id), id, ...data });
return id;
};
}
Expand Down
6 changes: 6 additions & 0 deletions website/src/pages/toast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ const toastId = toast('Event has been created');
toast.dismiss(toastId);
```

You can also dismiss all toasts at once by calling `toast.dismiss()` without an id.

```jsx
toast.dismiss();
```

## API Reference

| Property | Description | Default |
Expand Down

1 comment on commit 8a17c96

@vercel
Copy link

@vercel vercel bot commented on 8a17c96 Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.