@impulse-ui-native/data-state
v2.0.1
Published
Reusable loading, empty, error, and content-state composition for data-backed screens.
Readme
@impulse-ui-native/data-state
Reusable loading, empty, error, and content-state composition for data-backed screens.
Installation
pnpm add @impulse-ui-native/data-stateMain exports
LoadingViewswaps content for a caller-provided loading component.EmptyViewrenders empty-state copy and primary or secondary actions whenisEmptyis true.ErrorViewrenders error-state copy and actions when an error is present.DataViewcoordinates loading, error, empty, and successful-content states in one component.- Public prop types describe each state view and its action footer.
Usage
import { ActivityIndicator } from "react-native";
import { DataView } from "@impulse-ui-native/data-state";
<DataView
loading={query.isLoading}
error={query.error}
isEmpty={!query.data?.length}
LoadingComponent={ActivityIndicator}
errorViewProps={{
text: "Could not load projects.",
primaryActionLabel: "Try again",
onPressPrimaryAction: query.refetch,
}}
emptyViewProps={{
text: "No projects yet.",
primaryActionLabel: "Create project",
onPressPrimaryAction: openCreateProject,
}}
>
<ProjectList projects={query.data ?? []} />
</DataView>;The views use component tokens from ThemeProvider for their layout, layering, and presentation.
