@tanstack/react-router 0.0.1-beta.162 → 0.0.1-beta.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.162",
4
+ "version": "0.0.1-beta.164",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -43,8 +43,8 @@
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@gisatcz/cross-package-react-context": "^0.2.0",
46
- "@tanstack/router-core": "0.0.1-beta.162",
47
- "@tanstack/react-store": "0.0.1-beta.162"
46
+ "@tanstack/router-core": "0.0.1-beta.164",
47
+ "@tanstack/react-store": "0.0.1-beta.164"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/index.tsx CHANGED
@@ -40,6 +40,8 @@ import {
40
40
  //
41
41
 
42
42
  export * from '@tanstack/router-core'
43
+ export * from './scroll-restoration'
44
+
43
45
  export { useStore }
44
46
 
45
47
  declare module '@tanstack/router-core' {
@@ -0,0 +1,27 @@
1
+ import * as React from 'react'
2
+ import {
3
+ ScrollRestorationOptions,
4
+ restoreScrollPositions,
5
+ watchScrollPositions,
6
+ } from '@tanstack/router-core'
7
+ import { useRouter } from '.'
8
+
9
+ const useLayoutEffect =
10
+ typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
11
+
12
+ export function useScrollRestoration(options?: ScrollRestorationOptions) {
13
+ const router = useRouter()
14
+
15
+ useLayoutEffect(() => {
16
+ return watchScrollPositions(router, options)
17
+ }, [])
18
+
19
+ useLayoutEffect(() => {
20
+ restoreScrollPositions(router, options)
21
+ })
22
+ }
23
+
24
+ export function ScrollRestoration(props: ScrollRestorationOptions) {
25
+ useScrollRestoration(props)
26
+ return null
27
+ }