Express CSV Logo

API Reference

useExpressCSV(options)

function useExpressCSV<TSchema>(
  options: UseExpressCSVOptions<TSchema>
): {
  open: (options: OpenOptions<Infer<TSchema>>) => void;
  close: () => void;
  restart: () => void;
  widgetState: WidgetState;
  isOpen: boolean;
  isReady: boolean;
  canRestart: boolean;
  lastError: Error | null;
  connectionStatus: string;
};

Options

OptionTypeRequiredDefaultDescription
schemaSchemaYesSchema definition created with x.row()
publishableKeystringYesYour publishable key from the dashboard
importIdentifierstringYesUnique identifier for this import type
titlestringNoTitle shown in the widget header
preloadbooleanNotruePreload widget in a hidden iframe for instant display
debugbooleanNofalseEnable debug logging
themeECSVThemeNoTheme variable overrides (see Styling)
colorModeColorModePrefNo'light', 'dark', or 'system'
customCSSstringNoCustom CSS injected into the widget
fontsRecord<string, ECSVFontSource>NoCustom font sources
stepDisplay'progressBar', 'segmented', or 'numbered'No'progressBar'Step indicator style
previewSchemaBeforeUploadbooleanNotrueShow expected columns before upload
templateDownloadTemplateDownloadConfigNoOffer downloadable template files
saveSessionbooleanNoPersist session for resuming interrupted imports
localeDeepPartial<ExpressCSVLocaleInput>NoLocale string overrides (see Localization)
disableStatusStepbooleanNoSkip the success/error status screen

Return Values

PropertyTypeDescription
open(options: OpenOptions<T>) => voidOpens the widget. Requires at least one of onData or webhook.
close() => voidCloses the widget
restart() => voidResets and reopens the widget for a new import
widgetStateWidgetStateCurrent widget state (reactive)
isOpenbooleantrue while the widget is open
isReadybooleantrue when the widget is initialized and ready to open
canRestartbooleantrue when the widget can be restarted
lastErrorError or nullMost recent error, or null
connectionStatusstringIframe connection status

open(options)

Options passed to open(). At least one of onData or webhook must be provided.

OptionTypeRequiredDescription
onData(chunk: RecordsChunk<T>, next: () => void) => void or Promise<void>*Callback for each chunk. Call next() to receive the next chunk.
webhookWebhookConfig*Webhook endpoint for server-side delivery (see Webhooks)
chunkSizenumberNoRecords per chunk (default: 1000)
onComplete() => voidNoCalled when all chunks have been processed
onCancel() => voidNoCalled when the user cancels the import
onError(error: Error) => voidNoCalled when an error occurs
onWidgetOpen() => voidNoCalled when the widget opens
onWidgetClose(reason: string) => voidNoCalled when the widget closes
onStepChange(stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => voidNoCalled when the wizard step changes

* At least one of onData or webhook is required.


RecordsChunk<T>

interface RecordsChunk<T> {
  records: T[];
  totalChunks: number;
  currentChunkIndex: number;
  totalRecords: number;
}
PropertyTypeDescription
recordsT[]Validated records for this chunk, typed from your schema
totalChunksnumberTotal number of chunks in the delivery
currentChunkIndexnumber0-based index of the current chunk
totalRecordsnumberTotal records across all chunks

WebhookConfig

interface WebhookConfig {
  url: string;
  headers?: Record<string, string>;
  method?: "POST" | "PUT" | "PATCH";
  timeout?: number;
  retries?: number;
  metadata?: Record<string, unknown>;
  awaitWebhookArrival?: boolean;
}

See Webhooks for payload structure and server handling.


WidgetState

The widget moves through these states during its lifecycle:

StateDescription
UNINITIALIZEDInitial state before the widget iframe is created
INITIALIZINGIframe is loading and establishing a connection
READYWidget is loaded, preloaded, and ready to be opened
OPENINGopen() has been called; creating an import session
OPENWidget is visible and the user is interacting with it
CLOSINGWidget is in the process of closing
RESETTINGWidget is resetting for a new import
ERRORAn error occurred (check lastError)
DESTROYEDWidget has been destroyed (component unmounted)

Typical flow: UNINITIALIZEDINITIALIZINGREADYOPENINGOPENCLOSINGREADY


ExpressCSVStep

The wizard step IDs passed to onStepChange:

Step IDDescription
'upload'File upload and optional schema preview
'select-sheet'Sheet selection (multi-sheet files only)
'select-header'Header row selection
'match-columns'Map CSV columns to schema fields
'match-options'Map option values for select/multiselect fields
'review'Review, edit, and validate data before import

Preloading

When preload is true (the default), the widget iframe is created immediately and loads in the background. This means open() displays the widget instantly with no loading screen.

When preload is false, the iframe is only created when open() is called. The user sees a brief loading indicator while the widget initializes.

Use preload: false if the import flow is rarely used and you want to avoid the upfront iframe cost.


Exported Types

All of these are importable from @expresscsv/react:

TypeDescription
Infer<TSchema>Extracts the row type from a schema
UseExpressCSVOptionsOptions for useExpressCSV()
OpenOptionsOptions for open()
RecordsChunkChunk delivered to onData
WebhookConfigWebhook delivery configuration
DeliveryOptionsBase delivery options
ECSVThemeTheme variable overrides (single or dual-mode)
ColorModePref'light', 'dark', or 'system'
ECSVFontSourceFont source (Google or custom URL)
TailwindThemeVarsTheme variable names
WidgetStateWidget state enum
WidgetModeWidget mode enum
ExpressCSVStepWizard step IDs
TemplateDownloadConfigTemplate download configuration
TemplateDownloadFormat'csv' or 'xlsx'
ExpressCSVLocaleInputFull locale type
DeepPartialDeep partial utility type
ImportCancelledErrorError thrown when import is cancelled
xSchema builder (value, not a type)

On this page