Skip to content

Commit

Permalink
Added state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtuevo committed Oct 22, 2024
1 parent e84f076 commit b2b61b7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/packages/components/src/components/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ interface ToastProps {
}

const Toast: React.FC<ToastProps> = ({message, primary, secondary, duration = 5000 }) => {
const [open, setOpen] = useState(true);
const toastStateAtom = atom({
key: "open",
default: true,
});

const [open, setOpen] = useRecoilState(toastStateAtom); // State management for toast visibility

const handleClose = (event, reason) => {
if (reason === "clickaway") {
Expand All @@ -20,11 +25,11 @@ const Toast: React.FC<ToastProps> = ({message, primary, secondary, duration = 50
};

const action = (
<div>
{primary}
{secondary}
</div>
);
<div>
{primary(setOpen)} {/* Pass setOpen to primary button */}
{secondary(setOpen)} {/* Pass setOpen to secondary button */}
</div>
);

return (
<Snackbar
Expand Down

0 comments on commit b2b61b7

Please sign in to comment.