Created
January 12, 2020 21:17
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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