"use client"; import { useEffect, useState } from "react"; import { X } from "lucide-react"; import { Button } from "@/components/ui/button"; interface InfoBannerProps { message: string; id: string; } export function InfoBanner({ message, id }: InfoBannerProps) { const [isVisible, setIsVisible] = useState(false); // Default hidden to avoid flash const [shouldRender, setShouldRender] = useState(false); useEffect(() => { // Delay check slightly to allow mount and avoid synchronous update warning // This also ensures we are safely on the client const timer = setTimeout(() => { const dismissed = localStorage.getItem(`banner-dismissed-${id}`); if (!dismissed) { setIsVisible(true); } setShouldRender(true); }, 0); return () => clearTimeout(timer); }, [id]); const handleDismiss = () => { setIsVisible(false); localStorage.setItem(`banner-dismissed-${id}`, "true"); }; if (!shouldRender || !isVisible) return null; return (
{message} {message} {message} {message}
); }