Skip to content

Instantly share code, notes, and snippets.

@aibolik
Created January 12, 2020 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aibolik/ebbf26f89a1b6adff5c6245fcba2f4d0 to your computer and use it in GitHub Desktop.
Save aibolik/ebbf26f89a1b6adff5c6245fcba2f4d0 to your computer and use it in GitHub Desktop.
Toast component with dismiss logic (part of https://aibolik.github.io/blog/creating-toast-api-with-react-hooks)
const Toast = ({ children, id }) => {
const { removeToast } = useToast();
useEffect(() => {
const timer = setTimeout(() => {
removeToast(id);
}, 3000); // delay
return () => {
clearTimeout(timer);
};
}, [id, removeToast]);
// ...render toast content as before...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment