File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
packages/react-router/src Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22
33import { TSR_DEFERRED_PROMISE , defer } from '@tanstack/router-core'
4- import type { DeferredPromise } from '@tanstack/router-core'
54
65export type AwaitOptions < T > = {
76 promise : Promise < T >
87}
98
109/** Suspend until a deferred promise resolves or rejects and return its data. */
11- export function useAwaited < T > ( {
12- promise : _promise ,
13- } : AwaitOptions < T > ) : [ T , DeferredPromise < T > ] {
10+ export function useAwaited < T > ( { promise : _promise } : AwaitOptions < T > ) : T {
11+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12+ if ( React . use ) {
13+ const data = React . use ( _promise )
14+ return data
15+ }
1416 const promise = defer ( _promise )
1517
1618 if ( promise [ TSR_DEFERRED_PROMISE ] . status === 'pending' ) {
@@ -21,7 +23,7 @@ export function useAwaited<T>({
2123 throw promise [ TSR_DEFERRED_PROMISE ] . error
2224 }
2325
24- return [ promise [ TSR_DEFERRED_PROMISE ] . data , promise ]
26+ return promise [ TSR_DEFERRED_PROMISE ] . data
2527}
2628
2729/**
@@ -47,7 +49,7 @@ function AwaitInner<T>(
4749 children : ( result : T ) => React . ReactNode
4850 } ,
4951) : React . JSX . Element {
50- const [ data ] = useAwaited ( props )
52+ const data = useAwaited ( props )
5153
5254 return props . children ( data ) as React . JSX . Element
5355}
Original file line number Diff line number Diff line change @@ -79,7 +79,12 @@ export function lazyRouteComponent<
7979 }
8080
8181 if ( ! comp ) {
82- throw load ( )
82+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
83+ if ( React . use ) {
84+ React . use ( load ( ) )
85+ } else {
86+ throw load ( )
87+ }
8388 }
8489
8590 return React . createElement ( comp , props )
You can’t perform that action at this time.
0 commit comments