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

324
Views
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 answers
Answer question

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 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!