useKivaDataSourceFields
Lightweight schema hook for one Kiva data source on React Native. Returns the data source and its field list (including inline enum options), served cache-first from the shared inventory so no extra request is made after the post-sign-in warm-up.
Installation
pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-kiva-data-source-fieldspnpm add @kivacore/api-client @kivacore/app-utils @tanstack/react-queryThis hook is native-only. Web components that only need the field list (bulk update, import wizard, dummy-data generator) take it from the much larger useKivaFormView / useKivaDataViewSelect hooks. On native, BulkUpdateDialog, useKivaDataImportWizard and useKivaDummyDataGeneratorWizard use this hook instead.
It needs a QueryClientProvider above it. The fetch runs through createDataSourceClient(client, { inventory: getSharedKivaInventory(client) }):
getBySlug(appSlug, dataSourceSlug)is served from the shared inventory withfieldsand inline enum options.- On a cache miss the scoped GET has no fields (system data sources), so the hook fetches again with
{ expand: 'enums' }.
All consumers share the query key ['kiva', 'dataSourceFields', appSlug, dataSourceSlug] (exported as kivaDataSourceFieldsQueryKey), so mounting the hook in several places causes a single request.
Usage
import { useKivaClient } from '@kivacore/signin/react-native';
import { useKivaDataSourceFields } from '@/hooks/kiva-native/use-kiva-data-source-fields';
export function TaskFieldList() {
const client = useKivaClient();
const { fields, isLoading, error } = useKivaDataSourceFields({
client,
appSlug: 'base',
dataSourceSlug: 'task'
});
if (isLoading) return <Spinner />;
if (error) return <Text>{error.message}</Text>;
return fields.map(field => <Text key={field.slug}>{`${field.name} · ${field.type}`}</Text>);
}Gating and pre-resolved fields
// Only fetch while a sheet is open
useKivaDataSourceFields({ client, appSlug, dataSourceSlug, enabled: open });
// Reuse fields you already have: the fetch is skipped entirely
useKivaDataSourceFields({ client, appSlug, dataSourceSlug, fields: gridFields });API Reference
Options (UseKivaDataSourceFieldsOptions)
| Option | Type | Default | Description |
|---|---|---|---|
client | RestApiClient | null | undefined | — | Authenticated REST client. The query waits while it is missing (required). |
appSlug | string | — | App slug (required). |
dataSourceSlug | string | — | Data source slug (required). |
enabled | boolean | true | Gate the fetch (for example only while a dialog is open). |
fields | ReadonlyArray<KivaFieldLike> | — | Pre-resolved fields. When set, nothing is fetched and these are returned. |
staleTime | number | 300000 (5 minutes) | React Query stale time (ms). |
Result (UseKivaDataSourceFieldsResult)
| Field | Type | Description |
|---|---|---|
dataSource | DataSource | null | The data source record from @kivacore/app-utils. |
fields | ReadonlyArray<KivaFieldLike> | Its fields, or the fields option. Empty while loading. |
isLoading | boolean | First load in progress (always false with pre-resolved fields). |
error | Error | null | Fetch error. |
refetch | () => void | Refetch the schema. |
KivaFieldLike
| Field | Type | Description |
|---|---|---|
id | string | Field id. |
slug | string | Field slug. |
name | string | Display name. |
type | IFieldType | string | Field type (field-text, field-select, …). |
options | unknown | Raw field options. |
enums | unknown | Inline enum options. |
[key: string] | unknown | Any other schema keys. |
Exports
| Export | Description |
|---|---|
useKivaDataSourceFields(options) | The hook. |
kivaDataSourceFieldsQueryKey(appSlug, dataSourceSlug) | Shared query key, for example to invalidate the schema after a studio change. |
Type Exports
| Type | Description |
|---|---|
UseKivaDataSourceFieldsOptions | Hook options. |
UseKivaDataSourceFieldsResult | Hook result. |
useKivaDataImportWizard
One-call wiring of a Kiva data source to the native DataImportWizard. Picks a spreadsheet, uploads and analyses it on the server, auto-maps columns, imports the rows and returns a ready-to-render wizard element plus imperative helpers.
useKivaDataSourceJsonSchema
Generate a JSON Schema (object schema, properties keyed by field slug) from a Kiva data source field list.