Skip to content

Instantly share code, notes, and snippets.

@aibolik
Created January 12, 2020 21:09
Show Gist options
  • Select an option

  • Save aibolik/d425843010c8897b8786211b4c489f56 to your computer and use it in GitHub Desktop.

Select an option

Save aibolik/d425843010c8897b8786211b4c489f56 to your computer and use it in GitHub Desktop.
addToast function in ToastProvider component(part of posts https://aibolik.github.io/blog/creating-toast-api-with-react-hooks)
let id = 0;
const ToastProvider = ({ children }) => {
// ...
const addToast = useCallback(content => {
setToasts(toasts => [
...toasts,
{ id: id++, content }
]);
}, [setToasts]);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment