UNPKG

phx-react

Version:

PHX REACT

31 lines 941 B
import { useEffect, useState } from 'react'; export const DEFAULT_ALERT_STATE = { message: '', isFailure: false, show: false, type: 'add', }; export const useShowNotification = () => { const [notification, setNotification] = useState(DEFAULT_ALERT_STATE); const onShowNotification = (data) => { setNotification((prev) => ({ ...prev, ...data })); }; const onHideNotification = () => { setNotification(DEFAULT_ALERT_STATE); }; useEffect(() => { if (notification.show) { const timerId = setTimeout(() => { setNotification((pre) => ({ ...pre, show: false, isFailure: false })); }, 5000); return () => clearTimeout(timerId); } return; }, [notification.show]); return { notification, onShowNotification, onHideNotification, }; }; //# sourceMappingURL=use-show-notification.js.map