From bf125ce87d2df37cd46f2e21662f6be5be5cc79a Mon Sep 17 00:00:00 2001 From: Mouignihazi <165266469+Mouignihazi@users.noreply.github.com> Date: Wed, 12 Aug 2026 00:42:43 +0200 Subject: [PATCH] Fix : CookieBanner useEffect --- src/components/CookieBanner.tsx | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/components/CookieBanner.tsx b/src/components/CookieBanner.tsx index 6384759..feae921 100644 --- a/src/components/CookieBanner.tsx +++ b/src/components/CookieBanner.tsx @@ -1,33 +1,33 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Link } from "react-router-dom"; - import styles from "../styles/CookieBanner.module.css"; -const COOKIE_CONSENT_KEY = "cookieConsentAccepted"; +const KEY = "cookieConsentAccepted"; export default function CookieBanner() { - const [accepted, setAccepted] = useState(() => { - return typeof window !== "undefined" && window.localStorage.getItem(COOKIE_CONSENT_KEY) === "true"; - }); + const [visible, setVisible] = useState(false); + + useEffect(() => { + const consent = localStorage.getItem(KEY); + if (!consent) { + setVisible(true); + } + }, [setVisible]); const handleAccept = () => { - if (typeof window !== "undefined") { - window.localStorage.setItem(COOKIE_CONSENT_KEY, "true"); - } - setAccepted(true); + localStorage.setItem(KEY, "true"); + setVisible(false); }; - if (accepted) { - return null; - } + if (!visible) return null; return (
- Ce site utilise des cookies pour améliorer votre expérience utilisateur et analyser le trafic. - En poursuivant votre navigation, vous acceptez l'utilisation des cookies. + Ce site utilise des cookies pour améliorer votre expérience utilisateur + et analyser le trafic. En poursuivant votre navigation, vous acceptez + l'utilisation des cookies.
-
En savoir plus @@ -38,4 +38,4 @@ export default function CookieBanner() {
); -} +} \ No newline at end of file