|
1
|
"use client" |
|
2
|
|
|
3
|
import { useEffect } from "react" |
|
4
|
import { useScrollController } from "docs-ui" |
|
5
|
|
|
6
|
/** |
|
7
|
* Resets the scroll container to the top on mount. `#main` lives in the |
|
8
|
* persistent layout, so its scroll position is retained across client |
|
9
|
* navigation. Tag/operation and intro-section pages scroll to their own target, |
|
10
|
* but the area index (`/[area]`) has none — without this it would inherit the |
|
11
|
* previous page's offset (appearing "scrolled down" by the navbar height). |
|
12
|
*/ |
|
13
|
const ScrollToTop = () => { |
|
14
|
const { scrollableElement } = useScrollController() |
|
15
|
|
|
16
|
useEffect(() => { |
|
17
|
if (!scrollableElement) { |
|
18
|
return |
|
19
|
} |
|
20
|
|
|
21
|
scrollableElement.scrollTo({ top: 0 }) |
|
22
|
}, [scrollableElement]) |
|
23
|
|
|
24
|
return null |
|
25
|
} |
|
26
|
|
|
27
|
export default ScrollToTop |