Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

325
Vistas
Mobile menu cloe after transition end

I have a problem with React. I would like my mobile menu to close only after the end of the transition on my last span of the Hover-Clone div.

I managed to do something but every second I reopen the menu it closes automatically.

I don't understand how I can make it work? Should I use useTransition, useRef, useHook?

Header.jsx

const [isActive, setIsActive] = useState(false);

  const showNavBar = () => {
    setIsActive(!isActive);
  };

  const spanEnd = document.querySelectorAll('.end');

  spanEnd.forEach(l => {
    if (isActive === true) {
      l.addEventListener('transitionend', () => {
        showNavBar();
      });
    }
  }); 

 <nav className={isActive ? Style.navBarMobile : Style.navBar}>
    <ul className={Style.navBarList}>
      <li className={Style.navBarListItem}>
        <NavLink className={Style.navBarListLink} to='/a_propos'>
          <div className={Style.original}>
            <span>à</span>
            <span>&nbsp;</span>
            <span>p</span>
            <span>r</span>
            <span>o</span>
            <span>p</span>
            <span>o</span>
            <span>s</span>
          </div>
          <div className={Style.hoverClone}>
            <span>à</span>
            <span>&nbsp;</span>
            <span>p</span>
            <span>r</span>
            <span>o</span>
            <span>p</span>
            <span>o</span>
            <span className='end'>s</span>
          </div>
        </NavLink>
      </li>

Kind Regards

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Disclaimer: I'm not a react beast

Your showNavBar method isn't actually showing the navbar, but rather toggling it. If it's closed, it will open it, if opened, it will close it.

  • If you want that, you should probably rename your method for clarity (toggleNavBar)
  • If you want it to really do what is says (which is my guess), you should update the content with setIsActive(true) instead

Give the second option a try and see what happens

edit As a matter of fact you probably still need the toggle option for the open/close button

So you could do

const ToggleNavBar = (to = null) => {
    const end_state = to === null ? !isActive : to
    
    setIsActive(end_state);
  };

then use it for your button like

// ...
onClick={toggleNavBar}
// ...

And for your span loop

//...
toggleNavBar(true)
//...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda