From b403ff2b139de724d9d4f656f1cae8933f7ad2f1 Mon Sep 17 00:00:00 2001 From: Factiven Date: Fri, 28 Apr 2023 01:48:47 +0700 Subject: Editor List v0.1 --- components/useAlert.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 components/useAlert.js (limited to 'components/useAlert.js') 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; -- cgit v1.2.3