Open History to see the last commit
1import {
2 getElementScrollRestorationEntry,
3 setupScrollRestoration,
4} from '@tanstack/router-core'
5import { useRouter } from './useRouter'
6import type {
7 ParsedLocation,
8 ScrollRestorationEntry,
9 ScrollRestorationOptions,
10} from '@tanstack/router-core'
11β
12function useScrollRestoration() {
13 const router = useRouter()
14 setupScrollRestoration(router, true)
15}
16β
17/**
18 * @deprecated use createRouter's `scrollRestoration` option instead
19 */
20export function ScrollRestoration(_props: ScrollRestorationOptions) {
21 useScrollRestoration()
22β
23 if (process.env.NODE_ENV === 'development') {
24 console.warn(
25 "The ScrollRestoration component is deprecated. Use createRouter's `scrollRestoration` option instead.",
26 )
27 }
28β
29 return null
30}
31β
32export function useElementScrollRestoration(
33 options: (
34 | {
35 id: string
36 getElement?: () => Window | Element | undefined | null
37 }
38 | {
39 id?: string
40 getElement: () => Window | Element | undefined | null
41 }
42 ) & {
43 getKey?: (location: ParsedLocation) => string
44 },
45): ScrollRestorationEntry | undefined {
46 useScrollRestoration()
47β
48 return getElementScrollRestorationEntry(useRouter(), options)
49}