How to add or remove class to another element by ReactJS onClick?

import React from "react";
import "./styles.css";

export default function App() {
    const [show, setShow] = React.useState();
    return (
        <div className="App">
            <button className="add" onClick={() => setShow(true)}>
                Show
            </button>
            <button className="remove" onClick={() => setShow(false)}>
                Hide
            </button>
            <button className="toggle" onClick={() => setShow(!show)}>
                Toggle
            </button>
            <nav className={`nav ${show ? "show" : ""}`}>Navigation menu</nav>
        </div>
    );
}

“Thank you for taking the time to read the article. If you’re interested, you can learn more about me 🙂 I appreciate your attention and look forward to sharing more about myself with you. May your day be bug-free and your code compile on the first try!”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.