Files
reflector/www/app/(errors)/errorMessage.tsx

30 lines
821 B
TypeScript

"use client";
import { useError } from "./errorContext";
import { useEffect, useState } from "react";
const ErrorMessage: React.FC = () => {
const { error, setError } = useError();
const [isVisible, setIsVisible] = useState<boolean>(false);
useEffect(() => {
if (error) setIsVisible(true);
}, [error]);
if (!isVisible || !error) return null;
return (
<div
onClick={() => {
setIsVisible(false);
setError("");
}}
className="max-w-xs z-50 fixed top-16 right-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded transition-opacity duration-300 ease-out opacity-100 hover:opacity-75 cursor-pointer transform hover:scale-105"
role="alert"
>
<span className="block sm:inline">{error}</span>
</div>
);
};
export default ErrorMessage;