Files
Folo/packages/internal/utils/src/react.ts
T
Innei b07e2de01e fix: entry meta no title in breadcrumb and catch not found error
- Introduced a new higher-order component, withAppErrorBoundary, to wrap components with error boundary functionality.
- Created EntryNotFoundErrorFallback component to display a user-friendly message when an entry is not found.
- Updated error handling in EntryContent to utilize the new EntryNotFound error type.
- Added EntryContentFallback component to manage entry prefetching and loading states, enhancing user experience during data retrieval.

These changes improve error management and user feedback for entry-related issues.

Signed-off-by: Innei <tukon479@gmail.com>
2025-09-09 19:22:51 +08:00

32 lines
1016 B
TypeScript

import type { ComponentType, FC, ReactElement } from "react"
import { createElement, Suspense } from "react"
type FallbackOptions = ReactElement | ComponentType
interface WithSuspenseOptions {
fallback?: FallbackOptions
}
/**
* Higher-order component that wraps a component with React Suspense
* @param Component - The component to wrap with Suspense
* @param options - Configuration options for the Suspense wrapper
* @returns A new component wrapped with Suspense
*/
export function withSuspense<P extends object>(
Component: FC<P>,
options: WithSuspenseOptions = {},
): FC<P> {
const { fallback } = options
const WrappedComponent = (props: P) => {
const fallbackElement = typeof fallback === "function" ? createElement(fallback) : fallback
return createElement(Suspense, { fallback: fallbackElement }, createElement(Component, props))
}
WrappedComponent.displayName = `withSuspense(${Component.displayName || Component.name || "Component"})`
return WrappedComponent as FC<P>
}