Skip to content

Commit

Permalink
wrap toast in createRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed Aug 28, 2024
1 parent 3322479 commit 5b0f59e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/ui/src/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "solid-js";
import { Card } from "../card";

import { createRoot } from "solid-js";
import { Icon } from "../_index";
import { Button } from "../button";
import { tw } from "../tw";
Expand Down Expand Up @@ -193,16 +194,16 @@ function Toaster(props: { label: string }) {
}

function toast(element: () => JSX.Element, options?: ToastOptions) {
const toaster = useToastsController();
const child = children(element);
const item = toaster.add(child, options);
function cleanup() {
toaster.remove(item.id);
}
onCleanup(cleanup);
return {
cleanup,
};
return createRoot(() => {
const toaster = useToastsController();
const child = children(element);
const item = toaster.add(child, options);
return {
cleanup: () => {
toaster.remove(item.id);
},
};
});
}

export { toast, Toast, Toaster };
Expand Down

0 comments on commit 5b0f59e

Please sign in to comment.