import { useState, useRef, useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { Link } from 'react-router-dom'; import { useLogoutMutation } from '/src/api/apiSlice' export const UserBurger = () => { const username = useSelector( s => s.auth.username ); const [ logout ] = useLogoutMutation() const [open, setOpen] = useState(false); const toggleRef = useRef(null); const menuRef = useRef(null); useEffect(() => { const handleOutside = e => { if ( menuRef.current && !menuRef.current.contains(e.target) && toggleRef.current && !toggleRef.current.contains(e.target) ) { setOpen(false) } } document.addEventListener('mousedown', handleOutside) return () => document.removeEventListener('mousedown', handleOutside) }, []); return ( ) }