Skip to main content

useExporter

Runs a backend export (GET <resource>/export/) and downloads the returned file in the browser.

The export list action already wires it up through ExportButton. Use it directly when a custom control should trigger the same backend export.

Signature​

import {useExporter} from 'habarico';

const exporter = useExporter('eshop/product');

Parameters​

NameTypeDefaultDescription
resource (required)string—Resource in "service/resource" form; also names the fallback file (/ becomes _)

Returns​

(params: ExportParams) => Promise<void> — calls the export endpoint and triggers the download:

await exporter({format: 'csv', fields: ['name', 'price'], ids: [1, 2]});

ExportParams:

NameTypeDescription
format (required)stringExport format, e.g. csv
fieldsstring[]Restricts and orders the exported columns
idsIdentifier[]Exports exactly these records
filterFiltersConfigurationExports everything matching this filter (the getList filter format)
sortSortPayloadRow order, serialized like getList's order_by

Behaviour​

  • The file is downloaded under the name from the response's Content-Disposition header (RFC 5987 filename* included); without one it falls back to <resource>.<format>.
  • A 202 Accepted response means the export exceeded the synchronous threshold and runs in the background — the hook only shows the ra.notification.export_running info notification.
caution

The backend must expose Content-Disposition to the browser (CORS Access-Control-Expose-Headers), otherwise every download falls back to the generic <resource>.<format> name.

See also​