Skip to content

AsyncContent

Handles async data states (loading, error, empty, success).

Props

AsyncContentProps<T>

PropTypeRequiredDescription
isLoadingbooleanYesWhether data is loading
errorError | nullNoError object
dataT | null | undefinedNoData to render
isEmptybooleanNoOverride empty detection
childrenReactNode | (data: T) => ReactNodeYesContent or render function
loadingComponentReactNodeNoCustom loading UI
errorComponentReactNode | (error: Error) => ReactNodeNoCustom error UI
emptyComponentReactNodeNoCustom empty UI
onRetry() => voidNoRetry callback for error state

Example

tsx
<AsyncContent
  isLoading={isLoading}
  error={error}
  data={users}
  onRetry={refetch}
>
  {(users) => (
    <ul>
      {users.map(user => <li key={user.id}>{user.name}</li>)}
    </ul>
  )}
</AsyncContent>

State Priority

  1. Loading → shows loading component
  2. Error → shows error component
  3. Empty → shows empty component
  4. Success → renders children

See also