From 482b1c8db5cfeaa20d75ce92fcb10f3ca8433633 Mon Sep 17 00:00:00 2001 From: Factiven Date: Fri, 14 Apr 2023 00:07:02 +0700 Subject: Update 5th --- pages/lib/useNotify.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pages/lib/useNotify.js (limited to 'pages/lib/useNotify.js') diff --git a/pages/lib/useNotify.js b/pages/lib/useNotify.js new file mode 100644 index 0000000..e6ba7e6 --- /dev/null +++ b/pages/lib/useNotify.js @@ -0,0 +1,41 @@ +import { useState, useCallback } from "react"; +import { motion as m, AnimatePresence } from "framer-motion"; + +export const useNotification = () => { + const [showNotification, setShowNotification] = useState(false); + const [notificationMessage, setNotificationMessage] = useState(""); + + const show = useCallback( + (message) => { + setNotificationMessage(message); + setShowNotification(true); + setTimeout(() => { + setShowNotification(false); + }, 5000); + }, + [setNotificationMessage, setShowNotification] + ); + + const NotificationComponent = () => { + return ( + + {showNotification && ( + +
+ {notificationMessage} +
+
+ )} +
+ ); + }; + + return { Notification: NotificationComponent, show }; +}; -- cgit v1.2.3