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
12345678910111213141516171819202122232425262728293031323334353637383940import type { Child, FC, PropsWithChildren } from '../'import type { ErrorHandler, FallbackRender } from '../components'import { DOM_ERROR_HANDLER } from '../constants'import { Fragment } from './jsx-runtime'
/* eslint-disable @typescript-eslint/no-explicit-any */export const ErrorBoundary: FC< PropsWithChildren<{ fallback?: Child fallbackRender?: FallbackRender onError?: ErrorHandler }>> = (({ children, fallback, fallbackRender, onError }: any) => { const res = Fragment({ children }) ;(res as any)[DOM_ERROR_HANDLER] = (err: any) => { if (err instanceof Promise) { throw err } onError?.(err) return fallbackRender?.(err) || fallback } return res}) as any
export const Suspense: FC<PropsWithChildren<{ fallback: any }>> = (({ children, fallback,}: any) => { const res = Fragment({ children }) ;(res as any)[DOM_ERROR_HANDLER] = (err: any, retry: () => void) => { if (!(err instanceof Promise)) { throw err } err.finally(retry) return fallback } return res}) as any/* eslint-enable @typescript-eslint/no-explicit-any */