0
I want to toggle my button it works but the problem is I want to create a more responsive. when the device width is 440 px my sidebar will be closed. When we click the button that time it will show. how can I do it?
But here my method not working.
import React, { useState } from "react";
import SideBar from "./components/SideBar";
import "./App.css";
function App() {
const [sidebar, setSidebar] = useState(false);
const sideBarShowHide = (e) => {
e.preventDefault();
setSidebar(!sidebar);
};
if (window.matchMedia("max-width:440px").matches) {
setSidebar(!sidebar);
}
return (
<div className="App">
{sidebar || <SideBar />}
<button onClick={sideBarShowHide}>Hide/show</button>
</div>
);
}
export default App;
560 views