Hooks

useDocyrusDataExport

Server-side export of a Docyrus 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.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-data-export
Required Packages(4 packages)
pnpm add @docyrus/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 DocyrusDataExportMenu 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 { useDocyrusClient } from '@docyrus/signin/react-native';

import { Button } from '@/components/docyrus-native/button';
import { useDocyrusDataExport } from '@/hooks/docyrus-native/use-docyrus-data-export';

export function ExportTasks({ dataSourceId, query, keyword }: Props) {
  const client = useDocyrusClient();
  const { exportData, isExporting, error } = useDocyrusDataExport({
    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:

KeyValue
dataSourceIdFrom the payload.
columns'*' when omitted, '*' or empty. Otherwise the slugs joined with , (inline projections such as country(id,name) are kept).
filtersThe RuleGroupType, or null when it has no rules.
limitpayload.limit when it is a positive number, otherwise defaultLimit.
filterKeywordOnly sent when non-empty.
any other keyForwarded 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 (UseDocyrusDataExportOptions)

OptionTypeDefaultDescription
clientRestApiClient—Authenticated REST client (required).
defaultLimitnumber10000Row cap when payload.limit is omitted.
endpointstring'/v1/edge/run/query-export'Export endpoint path.
fileNamestringexport-<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.
sharebooleantrueNative: open the share sheet after writing.

DocyrusDataExportPayload

FieldTypeDescription
dataSourceIdstringTarget data source id (required).
columns'*' | ReadonlyArray<string>'*' (or omitted) for every exportable field, or field slugs with optional inline projections.
filtersRuleGroupType | nullFilter group of the items query.
filterKeywordstringFree-text keyword search.
limitnumberMaximum rows. Defaults to defaultLimit.
format'xlsx' | 'csv'Export format (server-controlled, default xlsx).
[key: string]unknownExtra keys forwarded to the endpoint.

Result (UseDocyrusDataExportResult)

FieldTypeDescription
exportData(payload: DocyrusDataExportPayload) => Promise<DocyrusDataExportFileResult | null>Run the export and share the file. Resolves null when expo-file-system is missing.
isExportingbooleanTrue while the request runs.
errorError | nullLast error (cleared on every new attempt).

DocyrusDataExportFileResult

FieldTypeDescription
uristringLocal file:// URI in the cache directory.
fileNamestringFile name including the extension.
mimeTypestringMIME type.

Differences from web

  • Web calls client.download(), which saves through the browser. Native POSTs with responseType: 'arrayBuffer', writes the bytes with expo-file-system and shares them with expo-sharing.
  • exportData resolves the written file (DocyrusDataExportFileResult) instead of void.
  • Native adds the fileName and share options.

Type Exports

TypeDescription
UseDocyrusDataExportOptionsHook options.
UseDocyrusDataExportResultHook result.
DocyrusDataExportPayloadRequest payload.
DocyrusDataExportFileResultWritten file metadata.

On this page