useKivaDataExport
Server-side export of a Kiva data source on React Native. POSTs the column list, filters and keyword to the query-export endpoint, writes the returned xlsx or csv file into the cache directory and opens the share sheet.
Installation
pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-kiva-data-exportpnpm add @kivacore/api-client @react-querybuilder/core expo-file-system (optional) expo-sharing (optional)The hook needs an authenticated RestApiClient. Unlike useDataExport, which projects rows you already loaded, the server runs the full query and streams back the whole result set as a file. Pair it with KivaDataExportMenu for the column picker.
expo-file-system and expo-sharing are optional peers, loaded lazily through the internal lib/native-export helpers. Without expo-file-system, exportData resolves null. Without expo-sharing, the file is written but not shared.
Usage
import { useKivaClient } from '@kivacore/signin/react-native';
import { Button } from '@/components/kiva-native/button';
import { useKivaDataExport } from '@/hooks/kiva-native/use-kiva-data-export';
export function ExportTasks({ dataSourceId, query, keyword }: Props) {
const client = useKivaClient();
const { exportData, isExporting, error } = useKivaDataExport({
client: client!,
fileName: 'tasks'
});
return (
<Button
loading={isExporting}
onPress={() => void exportData({
dataSourceId,
columns: ['name', 'status(id,name)', 'due_date'],
filters: query,
filterKeyword: keyword
}).catch(() => undefined)}>
Export
</Button>
);
}Request body
exportData(payload) sends POST /v1/edge/run/query-export (or endpoint) with responseType: 'arrayBuffer' and this body:
| Key | Value |
|---|---|
dataSourceId | From the payload. |
columns | '*' when omitted, '*' or empty. Otherwise the slugs joined with , (inline projections such as country(id,name) are kept). |
filters | The RuleGroupType, or null when it has no rules. |
limit | payload.limit when it is a positive number, otherwise defaultLimit. |
filterKeyword | Only sent when non-empty. |
| any other key | Forwarded as is (for example format). |
The response bytes are written to <cache>/<fileName>.xlsx (or .csv when payload.format === 'csv') and handed to the share sheet. Errors are stored in error and re-thrown.
API Reference
Options (UseKivaDataExportOptions)
| Option | Type | Default | Description |
|---|---|---|---|
client | RestApiClient | — | Authenticated REST client (required). |
defaultLimit | number | 10000 | Row cap when payload.limit is omitted. |
endpoint | string | '/v1/edge/run/query-export' | Export endpoint path. |
fileName | string | export-<yyyy-mm-dd> | Native: file name without extension. The server's Content-Disposition is not reachable through client.post, so the name is chosen on the device. |
share | boolean | true | Native: open the share sheet after writing. |
KivaDataExportPayload
| Field | Type | Description |
|---|---|---|
dataSourceId | string | Target data source id (required). |
columns | '*' | ReadonlyArray<string> | '*' (or omitted) for every exportable field, or field slugs with optional inline projections. |
filters | RuleGroupType | null | Filter group of the items query. |
filterKeyword | string | Free-text keyword search. |
limit | number | Maximum rows. Defaults to defaultLimit. |
format | 'xlsx' | 'csv' | Export format (server-controlled, default xlsx). |
[key: string] | unknown | Extra keys forwarded to the endpoint. |
Result (UseKivaDataExportResult)
| Field | Type | Description |
|---|---|---|
exportData | (payload: KivaDataExportPayload) => Promise<KivaDataExportFileResult | null> | Run the export and share the file. Resolves null when expo-file-system is missing. |
isExporting | boolean | True while the request runs. |
error | Error | null | Last error (cleared on every new attempt). |
KivaDataExportFileResult
| Field | Type | Description |
|---|---|---|
uri | string | Local file:// URI in the cache directory. |
fileName | string | File name including the extension. |
mimeType | string | MIME type. |
Differences from web
- Web calls
client.download(), which saves through the browser. Native POSTs withresponseType: 'arrayBuffer', writes the bytes withexpo-file-systemand shares them withexpo-sharing. exportDataresolves the written file (KivaDataExportFileResult) instead ofvoid.- Native adds the
fileNameandshareoptions.
Type Exports
| Type | Description |
|---|---|
UseKivaDataExportOptions | Hook options. |
UseKivaDataExportResult | Hook result. |
KivaDataExportPayload | Request payload. |
KivaDataExportFileResult | Written file metadata. |
useKivaContactChannels
React Query wiring for the Contact Channels & Consent API — a record's channels, consent and validation ledgers, tenant brands and every channel / consent / validation mutation.
useKivaDataGallery
Kiva-backed card gallery for React Native — composes useKivaDataGrid for schema, saved views, server filters / sort / search / paging and pivot / side filters, and adds gallery-owned card + display config, a toolbar and props for the native DataGallery.