A
A
Artyom2022-04-15 17:56:42
React
Artyom, 2022-04-15 17:56:42

How to pass a function to a component in react?

There is a useState

const [menuTopActive, setMenuTopActive] = useState(false)

There is a Navbar component where I pass parameters with state
<Navbar topActive={menuTopActive} setTopActive={setMenuTopActive} />

There is a burger button with an onClick event (setTopActive and topActive passed to props). This is already Navbar.jsx
<div className="burger-btn" onClick={function () {
     
                setTopActive(!topActive)
            }}>
                <span/>
            </div>

Throws Uncaught TypeError: setTopActive is not a function

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question