diff options
| author | Factiven <[email protected]> | 2023-04-13 16:03:57 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-13 16:03:57 +0700 |
| commit | b365d89a11adf40d37b78292f121b890e960d0e8 (patch) | |
| tree | 6bd745c773dc48a2e5e4c18d2f71d54d82d682fd /lib/useNotify.js | |
| parent | update 1 (diff) | |
| download | moopa-b365d89a11adf40d37b78292f121b890e960d0e8.tar.xz moopa-b365d89a11adf40d37b78292f121b890e960d0e8.zip | |
update 2nd
Diffstat (limited to 'lib/useNotify.js')
| -rw-r--r-- | lib/useNotify.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/useNotify.js b/lib/useNotify.js new file mode 100644 index 0000000..e6ba7e6 --- /dev/null +++ b/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 ( + <AnimatePresence> + {showNotification && ( + <m.div + key="teasa" + transition={{ duration: 0.5 }} + initial={{ opacity: 0, y: 100 }} + animate={{ opacity: 1, y: 0 }} + exit={{ opacity: 0, y: 100 }} + className="z-50 fixed bottom-10 w-screen flex justify-center text-center" + > + <div className="bg-green-600 text-white px-2 py-2 font-bold rounded-[30px]"> + {notificationMessage} + </div> + </m.div> + )} + </AnimatePresence> + ); + }; + + return { Notification: NotificationComponent, show }; +}; |