Skip to content

Commit 764c084

Browse files
set scroll restoration to manual
1 parent 0f3d998 commit 764c084

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/app/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { ContextQuote } from '@/context/ContextQuote'
1111
import { ContextTopTenPosts } from '@/context/ContextTopTenPosts'
1212
import { ContextTopUsers } from '@/context/ContextTopUsers'
1313
import { useFocusTrap } from '@/hooks/useFocusTrap'
14+
import { useScrollRestoration } from '@/hooks/useScrollRestoration'
1415

1516
export default function Home() {
1617
const quoteRef = useRef<HTMLQuoteElement>(null)
1718
const topTenPostsRef = useRef<HTMLDivElement | null>(null)
1819
const topUsersRef = useRef<HTMLDivElement | null>(null)
1920

2021
useFocusTrap()
22+
useScrollRestoration()
2123

2224
return (
2325
<div className="min-h-svh flex flex-col items-center justify-start bg-gradient-to-b from-stone-700 to-stone-800">

src/hooks/useScrollRestoration.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
5+
export const useScrollRestoration = () => {
6+
useEffect(() => {
7+
if ('scrollRestoration' in window.history) {
8+
window.history.scrollRestoration = 'manual'
9+
}
10+
}, [])
11+
}

0 commit comments

Comments
 (0)