diff options
| author | Factiven <[email protected]> | 2023-04-28 01:48:47 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-28 01:48:47 +0700 |
| commit | b403ff2b139de724d9d4f656f1cae8933f7ad2f1 (patch) | |
| tree | fe74895e1b0b902327b28d7401bdb28248d774cf /components/useAlert.js | |
| parent | Merge branch 'main' into pre-production (diff) | |
| download | moopa-b403ff2b139de724d9d4f656f1cae8933f7ad2f1.tar.xz moopa-b403ff2b139de724d9d4f656f1cae8933f7ad2f1.zip | |
Editor List v0.1
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; |