@procore/labs-toast-alert
v4.0.0
Published
Displays a temporary Toast notification
Downloads
828
Maintainers
Keywords
Readme
Toast Alert
A package to display Core Toast
notifications.
Importing
import {
ToastAlertProvider,
useToastAlertContext,
} from "@procore/labs-toast-alert";
Usage
function App() {
return (
<ToastAlertProvider>
<ComponentWithToasts />
</ToastAlertProvider>
);
};
function ComponentWithToasts() {
const { showToast, hideAllToasts } = useToastAlertContext();
return (
<>
<button
onClick={() => {
showToast.success("Success toast description", {
afterClose: () => console.log("Success toast closed!"),
});
}}
>
Show Success Toast
</button>
<button
onClick={() => {
showToast.error("Error toast description");
}}
>
Show Error Toast
</button>
<button
onClick={() => {
hideAllToasts();
}}
>
Hide All Toasts
</button>
</>
);
};