Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda