mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-05-15 02:35:52 +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>
|
||
|
);
|
||
|
};
|