Created
January 12, 2020 21:11
-
-
Save aibolik/d960225e1c6f1951923c83ed7be00a88 to your computer and use it in GitHub Desktop.
removeToast in ToastProvider component (part of post https://aibolik.github.io/blog/creating-toast-api-with-react-hooks)
This file contains hidden or 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 ToastProvider = ({ children }) => { | |
| // ... | |
| const addToast = useCallback(content => { | |
| setToasts(toasts => [ | |
| ...toasts, | |
| { id: id++, content } | |
| ]); | |
| }, [setToasts]); | |
| const removeToast = useCallback(id => { | |
| setToasts(toasts => toasts.filter(t => t.id !== id)); | |
| }, [setToasts]); | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment