"use client"
import * as React from "react"
import { StateView } from "@/components/feedback/state-view"
export type AsyncBoundaryProps = React.PropsWithChildren<{
loading?: boolean
error?: unknown
empty?: boolean
loadingTitle?: React.ReactNode
errorTitle?: React.ReactNode
emptyTitle?: React.ReactNode
onRetry?: () => void
}>
function AsyncBoundary({
loading,
error,
empty,
loadingTitle = "Loading",
errorTitle = "Unable to load",
emptyTitle = "No data",
onRetry,
children,
}: AsyncBoundaryProps) {
if (loading) return
if (error) {
const description = error instanceof Error ? error.message : "Try again or check the request."
return
}
if (empty) return
return <>{children}>
}
export { AsyncBoundary }