Skip to content

Commit 93894a0

Browse files
committed
Replace MUI useScrollTrigger hook with simple hook
1 parent bf5f7e8 commit 93894a0

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/app/components/PageLayout/Header.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react'
2-
import useScrollTrigger from '@mui/material/useScrollTrigger'
32
import { useTheme } from '@mui/material/styles'
3+
import { useScrolled } from '../../hooks/useScrolled'
44
import { HomePageLink } from './Logotype'
55
import { NetworkSelector } from './NetworkSelector'
66
import { Button } from '@oasisprotocol/ui-library/src/components/ui/button'
@@ -16,24 +16,19 @@ export const Header: FC = () => {
1616
const { isDesktop } = useScreenSize()
1717
const scope = useScopeParam()
1818
const withScopeSelector = !!scope && isScopeSelectorNeeded(scope)
19-
const scrollTrigger = useScrollTrigger({
20-
disableHysteresis: true,
21-
threshold: 0,
22-
})
19+
const scrolled = useScrolled()
2320

2421
return (
2522
<header
26-
className="flex flex-col w-full box-border flex-shrink-0 sticky z-[1100] top-0 right-0 left-auto transition-colors duration-300 ease-in-out shadow-md"
23+
className="flex flex-col w-full box-border flex-shrink-0 sticky z-[1100] top-0 right-0 left-auto shadow-md"
2724
style={{
28-
backgroundColor: scrollTrigger
29-
? theme.palette.layout.contrastSecondary
30-
: theme.palette.layout.secondary,
25+
backgroundColor: theme.palette.layout.contrastSecondary,
3126
}}
3227
>
3328
<div className="px-4">
3429
<div className="grid grid-cols-12 pt-3 pb-4 px-0 md:px-[4%]">
3530
<div className="col-span-6 xl:col-span-3 flex items-center">
36-
<HomePageLink showText={!scrollTrigger && !isMobile} />
31+
<HomePageLink showText={!scrolled && !isMobile} />
3732
</div>
3833

3934
{withScopeSelector && (

src/app/hooks/useScrolled.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useEffect, useState } from 'react'
2+
3+
export function useScrolled(): boolean {
4+
const [scrolled, setScrolled] = useState(false)
5+
6+
useEffect(() => {
7+
const handleScroll = () => {
8+
setScrolled(window.scrollY > 0)
9+
}
10+
11+
handleScroll()
12+
window.addEventListener('scroll', handleScroll, { passive: true })
13+
14+
return () => window.removeEventListener('scroll', handleScroll)
15+
}, [])
16+
17+
return scrolled
18+
}

0 commit comments

Comments
 (0)