Skip to content

Commit b5384db

Browse files
Fixed a bug with nav and sidebar
1 parent e89dfde commit b5384db

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/App.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "./App.css";
2-
import { useState, useEffect } from "react";
2+
import { useState, useEffect, useLayoutEffect } from "react";
33
import Chart from "./components/Chart/Chart";
44
import Button from "./components/Button/Button";
55
import Navbar from "./components/Navbar/Navbar";
@@ -24,6 +24,16 @@ function App() {
2424
const [algType, setAlgType] = useState(0);
2525
const [showSidebar, setShowSidebar] = useState(false);
2626

27+
useLayoutEffect(() => {
28+
const updateState = () => {
29+
if (window.innerWidth >= 1000) setShowSidebar(false);
30+
};
31+
window.addEventListener("resize", updateState);
32+
return () => {
33+
window.removeEventListener("resize", updateState);
34+
};
35+
}, [showSidebar]);
36+
2737
useEffect(() => {
2838
const arr = generateArray(size);
2939
setCompleted([]);

0 commit comments

Comments
 (0)