Add suspenseWithOptions
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2025-07-21 11:35:02 +02:00
parent 30bd1a0180
commit b5f081044e
2 changed files with 20 additions and 2 deletions

View File

@@ -386,6 +386,24 @@ export const suspense = <T extends Component<any, any, P>, P extends {}>(
Object.getPrototypeOf(self), Object.getPrototypeOf(self),
) )
export const suspenseWithOptions: {
<T extends Component<any, any, P>, P extends {}>(
suspenseOptions: Partial<Suspense.Options>
): (
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
) => T & Suspense
<T extends Component<any, any, P>, P extends {}>(
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
suspenseOptions: Partial<Suspense.Options>,
): T & Suspense
} = Function.dual(2, <T extends Component<any, any, P>, P extends {}>(
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
suspenseOptions: Partial<Suspense.Options>,
): T & Suspense => Object.setPrototypeOf(
{ ...self, suspense: true, suspenseOptions },
Object.getPrototypeOf(self),
))
export const useFC: { export const useFC: {
<E, R, P extends {}>( <E, R, P extends {}>(

View File

@@ -20,7 +20,7 @@ const RouteComponent = Component.make(function* AsyncRendering() {
onChange={e => setInput(e.target.value)} onChange={e => setInput(e.target.value)}
/> />
<VMemoizedAsyncComponent /> <VMemoizedAsyncComponent fallback={<p>Loading memoized...</p>} />
<VAsyncComponent /> <VAsyncComponent />
</Flex> </Flex>
) )
@@ -61,7 +61,7 @@ const AsyncComponent = Component.make(function* AsyncComponent() {
</Flex> </Flex>
) )
}).pipe( }).pipe(
Component.suspense Component.suspenseWithOptions({ defaultFallback: <p>Loading...</p> })
) )
const MemoizedAsyncComponent = Component.memo(AsyncComponent) const MemoizedAsyncComponent = Component.memo(AsyncComponent)