remove nav listener on unmount

This commit is contained in:
Tom Heaton
2024-06-06 00:46:46 +01:00
parent 77da5694bb
commit 447bb82e2f
5 changed files with 17 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ export const Button = styled(Link)`
border-radius: 50px; border-radius: 50px;
background: ${({ primary }) => (primary ? "#01BF71" : "#010606")}; background: ${({ primary }) => (primary ? "#01BF71" : "#010606")};
white-space: nowrap; white-space: nowrap;
padding: ${({ big }) => (big ? " 14px 48px" : "12px 30px")}; padding: ${({ big }) => (big ? "14px 48px" : "12px 30px")};
color: ${({ dark }) => (dark ? "#010106" : "#fff")}; color: ${({ dark }) => (dark ? "#010106" : "#fff")};
font-size: $ ${({ fontBig }) => (fontBig ? "20px" : "16px")}; font-size: $ ${({ fontBig }) => (fontBig ? "20px" : "16px")};
outline: none; outline: none;

View File

@@ -1,4 +1,3 @@
import React from "react";
import img from "../../images/F23.prince.learning.turquoise.jpg"; import img from "../../images/F23.prince.learning.turquoise.jpg";
import { import {
HeroCitationBlock, HeroCitationBlock,
@@ -124,7 +123,7 @@ export default function HeroSection() {
<HeroCitationBlock> <HeroCitationBlock>
<pre> <pre>
<code> <code>
<React.Fragment>{citation}</React.Fragment> <>{citation}</>
</code> </code>
</pre> </pre>
</HeroCitationBlock> </HeroCitationBlock>

View File

@@ -15,6 +15,7 @@ import {
export default function NavBar({ toggle }) { export default function NavBar({ toggle }) {
const [scrollNav, setScrollNav] = useState(false); const [scrollNav, setScrollNav] = useState(false);
useEffect(() => {
const changeNav = () => { const changeNav = () => {
if (window.scrollY >= 80) { if (window.scrollY >= 80) {
setScrollNav(true); setScrollNav(true);
@@ -23,8 +24,11 @@ export default function NavBar({ toggle }) {
} }
}; };
useEffect(() => {
window.addEventListener("scroll", changeNav); window.addEventListener("scroll", changeNav);
return () => {
window.removeEventListener("scroll", changeNav);
};
}, []); }, []);
const toggleHome = () => { const toggleHome = () => {

View File

@@ -14,7 +14,7 @@ export const NotebookWrapper = styled.div`
display: grid; display: grid;
z-index: 1; z-index: 1;
/* height: 1250px; */ /* height: 1250px; */
width: 100% ; width: 100%;
max-width: 1100px; max-width: 1100px;
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
@@ -62,7 +62,7 @@ export const Column2 = styled.p`
` `
export const TextWrapper = styled.div` export const TextWrapper = styled.div`
max-width: 540px ; max-width: 540px;
padding-top: 0; padding-top: 0;
padding-bottom: 0; padding-bottom: 0;
` `

View File

@@ -5,7 +5,7 @@ export default function ScrollToTop() {
const { pathname } = useLocation(); const { pathname } = useLocation();
useEffect(() => { useEffect(() => {
window.scrollTo(0, 0, {}); window.scrollTo(0, 0, { behavior: "smooth" });
}, [pathname]); }, [pathname]);
return null; return null;