When the img is pressed the side menu opens fine but when i close the side menu and try to open it again by pressing the img it requires two clicks to open. how do i make it so it works with one click even after i open and close the side menu?
const Header = () => {
let [isOpen, setIsOpen] = useState(false);
return (
<header className='homepage-header'>
<img src={menusvg} alt='' onClick={() => setIsOpen((isOpen) => !isOpen)} />
{
isOpen ? <SideMenu /> : null
}
<h1>Main Header</h1>
</header>
)
}
note: i have another button inside the SideMenu componenet that closes the menu.
SideMenu:
function SideMenu() {
let [isOpen, setIsOpen] = useState(true);
return (
<>
{
isOpen ? <div className='side-menu'>
<p>side menue</p>
<i class="fas fa-times" onClick={() => setIsOpen((isOpen) => !isOpen)}></i>
</div>
: null
}
</>
)
}