Skip to content

Commit

Permalink
🎨 refactor header to use window position hook
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-manning committed Sep 16, 2021
1 parent ddc7f7a commit 77d984e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/ConnectorDesktop.tsx
Expand Up @@ -12,7 +12,7 @@ import { useWeb3Updated } from "../app/hooks/use-web3-updated";
import pending from "../assets/ui/status/pending.svg";
import { spinAnimation } from "../styles/animations/SpinAnimation";
import { pendingTransactionsCount } from "../state/transactionsSlice";
import { useWindowPosition } from "../app/hooks/use-window-position";
import useWindowPosition from "../app/hooks/use-window-position";

const StyledConnectorDesktop = styled.div`
display: flex;
Expand Down
20 changes: 4 additions & 16 deletions src/components/Header.tsx
@@ -1,11 +1,12 @@
import React, { useEffect, useState } from "react";
import React from "react";
import styled from "styled-components";
import { Link } from "react-router-dom";

import logo from "../assets/logo/logo.svg";
import Connector from "./Connector";
import NavItems from "./NavItems";
import Banner from "./Banner";
import useWindowPosition from "../app/hooks/use-window-position";

type HeaderProps = {
isSticky: boolean;
Expand Down Expand Up @@ -58,23 +59,10 @@ const Logo = styled.img`
`;

const Header = (): JSX.Element => {
const [scrollPosition, setScrollPosition] = useState(0);

const handleScroll = () => {
const position = window.pageYOffset;
setScrollPosition(position);
};

useEffect(() => {
window.addEventListener("scroll", handleScroll, { passive: true });

return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
const windowPosition = useWindowPosition();

return (
<StyledHeader isSticky={scrollPosition > 40}>
<StyledHeader isSticky={windowPosition > 40}>
<Banner />
<Content>
<Link to="/">
Expand Down

0 comments on commit 77d984e

Please sign in to comment.