DataContainer
A loading/error wrapper for async sections. When isLoading is true it shows a spinner or the brand AppLoader; when error is set it shows an alert; otherwise it renders children.
Previewβ
Live previewβ Open in Storybook
Importβ
import { DataContainer } from "@xocialive/ui-components";
import type { DataContainerProps } from "@xocialive/ui-components/components";
Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | β | Content rendered when not loading and no error |
isLoading | boolean | false | Shows the loading UI when true |
loadingType | "circular" | "app" | "none" | "app" | "circular" β centred spinner; "app" β full AppLoader; "none" β nothing |
error | any | β | RTK Query error object or Error. Shows an Alert with the error description |
customAppLoader | ReactNode | β | Replaces the default AppLoader when loadingType is "app" |
animationData | object | β | Custom Lottie JSON for the default AppLoader |
textOverrides | DataContainerTexts | β | Label overrides for loading/error messages |
DataContainerTextsβ
interface DataContainerTexts {
loading?: string; // e.g. t("common.loading")
errorLoadingData?: string; // e.g. t("common.errorLoadingData")
unknownError?: string; // fallback when error has no message
}
Basic usageβ
src/modules/items/views/ListItems.tsx
import { DataContainer } from "@xocialive/ui-components";
<DataContainer
isLoading={isLoading}
textOverrides={{
loading: t("common.loading"),
}}
>
<PageListView ... />
</DataContainer>
With RTK Queryβ
import { DataContainer } from "@xocialive/ui-components";
const { data, isLoading, error } = useGetItemsQuery({});
<DataContainer isLoading={isLoading} error={error}>
<ItemsTable data={data?.body || []} />
</DataContainer>;
With circular spinnerβ
Use loadingType="circular" for small inline sections instead of the full-screen loader:
<DataContainer isLoading={isLoading} loadingType="circular">
<SomeSection />
</DataContainer>
Error displayβ
When error is set DataContainer reads error.data.description (RTK Query shape) or error.message and displays it in a MUI Alert:
<DataContainer error={query.error}>
<UserTable users={data} />
</DataContainer>
See alsoβ
AppLoaderβ standalone full-screen loaderErrorBoundaryDataViewContainer