30 lines
847 B
JavaScript
30 lines
847 B
JavaScript
'use client';
|
|
import { createContext, useState } from "react";
|
|
import Alert from "@/conponent/Alert";
|
|
|
|
export const Alertconstext = createContext();
|
|
|
|
const AlertProvider = ({ children }) => {
|
|
const [viuwAlert, setViuwAlert] = useState(false);
|
|
const [titulo, setTitulo] = useState('Alerta');
|
|
const [mensaje, setMensaje] = useState('');
|
|
|
|
const AlertWrapper = {
|
|
show: (titulo = 'Alerta', mensaje) => {
|
|
setTitulo(titulo);
|
|
setMensaje(mensaje);
|
|
setViuwAlert(true);
|
|
},
|
|
hide: () => setViuwAlert(false)
|
|
}
|
|
|
|
return (
|
|
<Alertconstext.Provider value={AlertWrapper}>
|
|
{children}
|
|
<Alert viuwAlert={viuwAlert} titulo={titulo} mensaje={mensaje} setViuwAlert={setViuwAlert} />
|
|
</Alertconstext.Provider>
|
|
)
|
|
};
|
|
|
|
export default AlertProvider;
|