import { useState, useEffect } from "react"; import Card from "../reusableCard/index"; import { addNote, showNotes, hideNotes } from "../../assets/SvgIcons/SvgIcons"; const StickyNote = () => { const [notes, setNotes] = useState([]); const [showNote, setShowNote] = useState(true); useEffect(() => { const savedNotes = JSON?.parse(localStorage?.getItem("stickyNotes")) || []; setNotes(savedNotes); }, []); const handleShowNote = () => { setShowNote(!showNote); }; const handleAddNote = () => { setNotes([...notes, { id: Date.now(), content: "" }]); //Reference }; const handleDeleteNote = (id) => { setNotes(notes?.filter((note) => note?.id !== id)); }; const handleSaveNote = (id, content) => { let notesData = notes?.map((note) => note?.id === id ? { ...note, content } : note ); setNotes(notesData); localStorage?.setItem("stickyNotes", JSON.stringify(notes)); }; return ( <>

Sticky Notes Application


{notes?.length > 0 ? ( notes ?.filter((note) => note?.content || showNote) ?.map((note) => ( handleDeleteNote(note?.id)} onSave={handleSaveNote} /> )) ) : (
No Notes are available. Click on "Add Note button"{" "} above to add
)}
); }; export default StickyNote;