Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
My menu icon doesn't get clicked whenever I place cursor on it

I've tried all methods still it doesn't work. I'm trying to build a website that has a menu icon showing up in mobile view such that when I click on it: it toggles!

import React, {useState} from 'react'
import {Link} from 'react-router-dom';
import './Navbar.css';
import { Button } from './Button';


function Navbar() {
    const {click, setClick} = useState(false);
    const {button, setButton} = useState(true);

    const handleClick = () => setClick(!click);
    const closeMobileMenu = () => setClick(false); 

    const showButton = () => {
        if(window.innerWidth <= 960){
            setButton(false);
        } else {
            setButton(true);
        }
    };

window.addEventListener("resize", showButton);

    return (
    
    
            </Link>
            <div className="menu-icon" onClick={handleClick}>
                <i className={click ? "fas fa-times" : "fas fa-bars"} /> 
            </div>
           
      
    )
}

export default Navbar
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

don't use div to handle onclick instead use input tag of submit or button tag

about 4 years ago · Juan Pablo Isaza Report

0

The useState hook returns a state variable and a handler function to set the state of the variable as an array, and not as an object. Hence, the returned variable and function should be destructed as an array as opposed to object destructuring that you're currently using. Array destructuring can be done using []. E.g, If a function returns an array [1,2,3], it can be destructured and assigned to different variables in one-go using array destructuring, like : const [a,b,c] = [1,2,3]

 const [click, setClick] = useState(false);
 const [button, setButton] = useState(true); //button and setButton in an array and not object.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!