aboutsummaryrefslogtreecommitdiff
path: root/components/useAlert.js
blob: fa82c42064d775de8e26cd3a158049de5bff1e75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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("");
      if (type === "success") {
        window.location.reload();
      }
    }, 3000);
  };

  return { message, type, showAlert };
};

export default useAlert;