From 672f64a61599241269f383853d7aebcc949e8d38 Mon Sep 17 00:00:00 2001 From: Sanidhya Kumar Verma Date: Sat, 27 Jan 2024 17:13:34 +0000 Subject: [PATCH] local storage added to banner states --- src/App.jsx | 2 +- src/components/Banner.jsx | 13 ++++++++++++- src/components/Navbar.jsx | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 1c3ce88..7b30dda 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { BrowserRouter } from "react-router-dom"; import { About, diff --git a/src/components/Banner.jsx b/src/components/Banner.jsx index a880bee..766b114 100644 --- a/src/components/Banner.jsx +++ b/src/components/Banner.jsx @@ -3,8 +3,14 @@ import { Link } from "react-router-dom"; import { close, bulb } from "../assets"; +const BANNER_KEY = "hide-banner"; + const Banner = ({ hide, setHide }) => { useEffect(() => { + const hideBanner = localStorage.getItem(BANNER_KEY); + + if (hideBanner) return; + const bannerTimer = setTimeout(() => { setHide(false); }, 5000); @@ -12,6 +18,11 @@ const Banner = ({ hide, setHide }) => { return () => clearTimeout(bannerTimer); }, []); + const handleBannerClose = () => { + setHide(true); + localStorage.setItem(BANNER_KEY, true); + }; + return (
{