diff options
Diffstat (limited to 'components/useAlert.js')
| -rw-r--r-- | components/useAlert.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/components/useAlert.js b/components/useAlert.js new file mode 100644 index 0000000..7426096 --- /dev/null +++ b/components/useAlert.js @@ -0,0 +1,20 @@ +import { useState } from "react"; + +const useAlert = () => { + const [message, setMessage] = useState(""); + const [type, setType] = useState(""); + + const showAlert = (message, type = "success") => { + setMessage(message); + setType(type); + setTimeout(() => { + setMessage(""); + setType(""); + window.location.reload(); + }, 5000); + }; + + return { message, type, showAlert }; +}; + +export default useAlert; |