States
Screen states that never lie: LoadingState (spinner or skeleton, busy, label for screen readers), ErrorState (alert, retry, collapsible details) and DataState, which picks loading, error, empty or your content from a status and never shows empty while pending or after an error.
Example
Projects
Your team's deployments.
- ApolloReadyDeployed 2 hours ago
- GeminiBuildingBuilding #1482
- MercuryFailedFailed 3 days ago
states-demo.tsxCopy code
Installation
Copy code
Usage
ImportCopy code
API reference
LoadingState
| Prop | Type | Default |
|---|---|---|
labelrequiredRead by screen readers, never shown. | string | – |
variant | "spinner" | "skeleton" | "spinner" |
rowsPlaceholder lines, with `variant="skeleton"`. | number | 3 |
size | EmptySize | "panel" |
Also takes <div> attributes except children.
ErrorState
Takes Omit<ComponentProps<"div">, "title"> &.
DataState
| Prop | Type | Default |
|---|---|---|
statusrequired | "pending" | "error" | "success" | – |
datarequiredThe result. Read only while `status` is success: data passed while pending is not shown. | T | undefined | – |
placeholderDataShown as content, marked busy, while pending before the first success, like cached or initial data. | T | – |
error | E | – |
isEmptyWhether successful data counts as empty. By default an empty array, `null` or `undefined` does. | (data: T) => boolean | – |
loadingReplaces the default LoadingState. | ReactNode | – |
keepPreviousDataKeeps showing the data of the last success while `status` is pending again, marked busy. Default true. | boolean | – |
fetchingA refetch in the background while `status` stays success, as some data libraries report it. | boolean | – |
labels | Partial<DataStateLabels> | { errorTitle: ReactNode; retry: ReactNode } | { errorTitle: ReactNode } | – |
size | EmptySize | – |
className | string | – |
childrenrequired | (data: T) => ReactNode | – |
renderError | (error: E, retry: (() => unknown) | undefined) => ReactNode | undefined | – |
onRetry | () => unknown | undefined | – |
Also takes <div> attributes except children, className.
Other exports
useLastSuccesstype LoadingStatePropstype ErrorStatePropstype DataStateLabelstype DataStatePropstype DataStatusAccessibility
- Never empty while pending or after an error; a refetch keeps the last data with aria-busy.
- ErrorState is an alert with a retry button and collapsible details.
Agent actions
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.