I've built a simple Navbar with a button inside the Navbar which makes the Navbar close on click - Now, I'd like to get the Navbar to re-open when I click on another button (note: this is not the same button as the one I close it with.
Here's my Navbar:
import React, { useState } from 'react';
export default function Navbar() {
const [showNav, setShowNav] = useState(true)
return (
<>
{showNav && <div className="w-48 bg-gray-200 h-screen py-10">
<button className="bg-primary w-32 h-12 rounded-lg text-white" onClick={() => setShowNav(false)}>Close Navbar</button>
<h1>Dashboard</h1>
<h2>Menu item</h2>
<h2>Menu item</h2>
<h2>Menu item</h2>
</div>
}
</>
)
}
Here's my App.js
import './App.css';
import Navbar from './components/Navbar';
import { useState } from 'react';
function App() {
const [showNav, setShowNav] = useState(true)
return (
<>
<div className="flex">
{showNav && <Navbar />}
<button className="bg-primary w-32 h-12 rounded-lg text-white" onClick={() => setShowNav(true)}>Open Navbar</button>
</div>
</>
);
}
export default App;