components.ts
This file
Path
src/jsx/dom/components.ts
39 lines · 1.1 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–39why, one step back1import type { Child, FC, PropsWithChildren } from '../'2import type { ErrorHandler, FallbackRender } from '../components'3import { DOM_ERROR_HANDLER } from '../constants'4import { Fragment } from './jsx-runtime'56/* eslint-disable @typescript-eslint/no-explicit-any */7export const ErrorBoundary: FC<8 PropsWithChildren<{9 fallback?: Child10 fallbackRender?: FallbackRender11 onError?: ErrorHandler12 }>13> = (({ children, fallback, fallbackRender, onError }: any) => {14 const res = Fragment({ children })15 ;(res as any)[DOM_ERROR_HANDLER] = (err: any) => {16 if (err instanceof Promise) {17 throw err18 }19 onError?.(err)20 return fallbackRender?.(err) || fallback21 }22 return res23}) as any2425export const Suspense: FC<PropsWithChildren<{ fallback: any }>> = (({26 children,27 fallback,28}: any) => {29 const res = Fragment({ children })30 ;(res as any)[DOM_ERROR_HANDLER] = (err: any, retry: () => void) => {31 if (!(err instanceof Promise)) {32 throw err33 }34 err.finally(retry)35 return fallback36 }37 return res38}) as any39/* eslint-enable @typescript-eslint/no-explicit-any */