@tanstack/react-router 0.0.1-beta.2 → 0.0.1-beta.200
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/LICENSE +21 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -19
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/awaited.js +45 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/index.js +66 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/react.js +642 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/scroll-restoration.js +56 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/esm/index.js +548 -2789
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +312 -37
- package/build/types/awaited.d.ts +8 -0
- package/build/types/index.d.ts +4 -73
- package/build/types/react.d.ts +200 -0
- package/build/types/scroll-restoration.d.ts +3 -0
- package/build/umd/index.development.js +2539 -2427
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +35 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +12 -10
- package/src/awaited.tsx +40 -0
- package/src/index.tsx +5 -624
- package/src/react.tsx +1228 -0
- package/src/scroll-restoration.tsx +27 -0
- package/build/cjs/react-router/src/index.js +0 -465
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2493
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.200",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
|
-
"homepage": "https://tanstack.com/router
|
|
7
|
+
"homepage": "https://tanstack.com/router",
|
|
8
8
|
"description": "",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"keywords": [
|
|
13
13
|
"react",
|
|
14
14
|
"location",
|
|
15
|
-
"@tanstack/react-router",
|
|
16
15
|
"router",
|
|
17
16
|
"routing",
|
|
18
17
|
"async",
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
25
24
|
},
|
|
26
25
|
"module": "build/esm/index.js",
|
|
27
|
-
"main": "build/cjs/
|
|
26
|
+
"main": "build/cjs/index.js",
|
|
28
27
|
"browser": "build/umd/index.production.js",
|
|
29
28
|
"types": "build/types/index.d.ts",
|
|
30
29
|
"engines": {
|
|
@@ -34,17 +33,20 @@
|
|
|
34
33
|
"build/**",
|
|
35
34
|
"src"
|
|
36
35
|
],
|
|
36
|
+
"sideEffects": false,
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=16",
|
|
39
39
|
"react-dom": ">=16"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"tiny-invariant": "^1.3.1",
|
|
44
|
+
"tiny-warning": "^1.0.3",
|
|
45
|
+
"@tanstack/react-store": "^0.0.1",
|
|
46
|
+
"@gisatcz/cross-package-react-context": "^0.2.0",
|
|
47
|
+
"@tanstack/router-core": "0.0.1-beta.200"
|
|
45
48
|
},
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"babel-plugin-transform-async-to-promises": "^0.8.18"
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "rollup --config rollup.config.js"
|
|
49
51
|
}
|
|
50
|
-
}
|
|
52
|
+
}
|
package/src/awaited.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DeferredPromise, isDehydratedDeferred } from '@tanstack/router-core'
|
|
2
|
+
import { useRouter } from './react'
|
|
3
|
+
|
|
4
|
+
export type AwaitOptions<T> = {
|
|
5
|
+
promise: DeferredPromise<T>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useAwaited<T>({ promise }: AwaitOptions<T>): [T] {
|
|
9
|
+
const router = useRouter()
|
|
10
|
+
|
|
11
|
+
let state = promise.__deferredState
|
|
12
|
+
const key = `__TSR__DEFERRED__${state.uid}`
|
|
13
|
+
|
|
14
|
+
if (isDehydratedDeferred(promise)) {
|
|
15
|
+
state = router.hydrateData(key)!
|
|
16
|
+
promise = Promise.resolve(state.data) as DeferredPromise<any>
|
|
17
|
+
promise.__deferredState = state
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (state.status === 'pending') {
|
|
21
|
+
throw promise
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (state.status === 'error') {
|
|
25
|
+
throw state.error
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
router.dehydrateData(key, state)
|
|
29
|
+
|
|
30
|
+
return [state.data]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Await<T>(
|
|
34
|
+
props: AwaitOptions<T> & {
|
|
35
|
+
children: (result: T) => JSX.Element
|
|
36
|
+
},
|
|
37
|
+
) {
|
|
38
|
+
const awaited = useAwaited(props)
|
|
39
|
+
return props.children(...awaited)
|
|
40
|
+
}
|