1

I have a hamburger toggle that I got from one template, but it seems I'm missing the 'activate on/off toggle' part because when I click the toggle nothing happens. What I'm missing?

<div data-testid="header">
    <header id="header" className="site-header">
        <div className="container">
          <div className="right-header">
            <nav className="main-menu">
              <button
                type="button"
                className="c-hamburger c-hamburger--htx"
              >
                <span />
              </button>
              <ul>
                <li>
                  <Link to="/news">
                    {headerText.news}
                    <i className="fa fa-caret-down" aria-hidden="true" />
                  </Link>
                </li>
             </div>
           </div>
         </header>
       </div>

And in the image is the template (where I got the code) working. It's only the htmlenter image description here

1
  • You need to hook the button to do something onClick Commented Jan 28, 2021 at 16:08

1 Answer 1

1

You would use a state to store the status of the menu.

const [hamburgerState, setHamburgerState] = useState(true);

And then:

<button type="button"
onClick={() => hamburgerState?setHamburgerState(false):setHamburgerState(true);}
className="c-hamburger c-hamburger--htx">
<span/>
</button>

Then you would use this state variable's value to change the visibility of the menu, usually by changing a className.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.