State Boundary

Consistent handling of loading, error, empty, and success states.

Quickstart

  1. Ensure the registry is set up in Installation.
  2. Run the registry command:
npx shadcn@latest add https://gen-ui-eta-two.vercel.app/r/state-boundary

Overview

State Boundary standardizes async state rendering with accessible defaults. It works with React Query, SWR, or any async state shape that provides data, isLoading, and error.

Basic Usage

import {
  StateBoundary,
  LoadingSkeleton,
  EmptyState,
  ErrorState,
} from "@/components/systems/state/state-boundary"

<StateBoundary
  state={query}
  loading={<LoadingSkeleton variant="card" />}
  empty={<EmptyState title="No users" description="Try adjusting your filters." />}
  error={({ error, retry }) => <ErrorState error={error} onRetry={retry} />}
>
  {({ data }) => <UserList users={data} />}
</StateBoundary>

Loading Behavior

Use loadingDelay and minLoadingDuration to avoid UI flicker. To keep data visible during refetches, setkeepPreviousData.

<StateBoundary
  state={query}
  loadingDelay={150}
  minLoadingDuration={400}
  keepPreviousData
>
  {({ data }) => <UserList users={data} />}
</StateBoundary>

Custom Empty Logic

Provide isEmpty when your data needs a custom empty check.

<StateBoundary
  state={query}
  isEmpty={(data) => data.items.length === 0}
>
  {({ data }) => <ItemGrid items={data.items} />}
</StateBoundary>

API Reference

PropTypeNotes
stateAsync stateSupports React Query, SWR, custom
loading / empty / errorReactNode | render propOverride UI states
onRetry() => voidRetry handler
loadingDelay / minLoadingDurationnumberReduce flicker
keepPreviousDatabooleanKeep content during refetch
isEmpty(data) => booleanCustom empty logic
← Previous: App LayoutNext: Motion System