mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-19 10:51:20 +00:00
22 lines
576 B
JavaScript
22 lines
576 B
JavaScript
import React, { createContext, useContext, useRef } from 'react';
|
|
import { Toast } from 'primereact/toast';
|
|
|
|
const ToastContext = createContext();
|
|
|
|
export const useToast = () => useContext(ToastContext);
|
|
|
|
export const ToastProvider = ({ children }) => {
|
|
const toast = useRef(null);
|
|
|
|
const showToast = (severity, summary, detail) => {
|
|
toast.current.show({ severity, summary, detail });
|
|
};
|
|
|
|
return (
|
|
<ToastContext.Provider value={{ showToast }}>
|
|
<Toast ref={toast} />
|
|
{children}
|
|
</ToastContext.Provider>
|
|
);
|
|
};
|