import React, { useState, useRef, useEffect } from 'react'; import { Link } from 'react-router-dom'; import Transition from '../utils/Transition'; function DropdownNotifications({ align }) { const [dropdownOpen, setDropdownOpen] = useState(false); const trigger = useRef(null); const dropdown = useRef(null); // close on click outside useEffect(() => { const clickHandler = ({ target }) => { if (!dropdown.current) return; if (!dropdownOpen || dropdown.current.contains(target) || trigger.current.contains(target)) return; setDropdownOpen(false); }; document.addEventListener('click', clickHandler); return () => document.removeEventListener('click', clickHandler); }); // close if the esc key is pressed useEffect(() => { const keyHandler = ({ keyCode }) => { if (!dropdownOpen || keyCode !== 27) return; setDropdownOpen(false); }; document.addEventListener('keydown', keyHandler); return () => document.removeEventListener('keydown', keyHandler); }); return (
setDropdownOpen(true)} onBlur={() => setDropdownOpen(false)} >
Notifications
  • setDropdownOpen(!dropdownOpen)} > 📣 Edit your information in a swipe Sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim. Feb 12, 2021
  • setDropdownOpen(!dropdownOpen)} > 📣 Edit your information in a swipe Sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim. Feb 9, 2021
  • setDropdownOpen(!dropdownOpen)} > 🚀Say goodbye to paper receipts! Sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim. Jan 24, 2020
) } export default DropdownNotifications;