Custom Toast question #1977
Answered
by
TimKolberger
jason-shen
asked this question in
General
-
Hi all just got a question if i create a custom toast, and i don't want it to auto close, i want to have a close button inside the toast, what function i need to call to close the toast from a button, sorry i am pretty new to this, i have try to read the docs but couldn't find where to achieve that thanks advance Jason |
Beta Was this translation helpful? Give feedback.
Answered by
TimKolberger
Sep 24, 2020
Replies: 1 comment 2 replies
-
You can use the default toast UI with disabling the auto close and the built-in close button: const CloseToastDemo = () => {
const toast = useToast();
function showToast() {
toast({
title: "Hello there",
isClosable: true, // shows a close button
duration: null // disables auto close
});
}
return <Button onClick={showToast}>Show Toast</Button>;
}; or you can define a custom render function for your toast and close it with the const CloseToastDemo = () => {
const toast = useToast();
function showToast() {
toast({
duration: null, // disables auto close
render: ({ onClose }) => (
<Box>
<Text>Hello there</Text>
<Button onClick={onClose}>Close Me</Button>
</Box>
)
});
}
return <Button onClick={showToast}>Show Toast</Button>;
};
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ljosberinn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the default toast UI with disabling the auto close and the built-in close button:
or you can define a custom render function for your toast and close it with the
onClose
function.