Express CSV Logo

SDK 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

OptionDescriptionTypeRequiredDefault
schemaSchema definition created with x.row()SchemaYes
publishableKeyYour publishable key from the dashboardstringYes
importIdentifierUnique identifier for this import typestringYes
titleTitle shown in the widget headerstringNo
preloadPreload widget in a hidden iframe for instant displaybooleanNotrue
debugEnable debug loggingbooleanNofalse
themeTheme variable overrides (see Styling)ECSVThemeNo
colorMode'light', 'dark', or 'system'ColorModePrefNo
customCSSCustom CSS injected into the widgetstringNo
fontsCustom font sourcesRecord<string, ECSVFontSource>No
stepDisplayStep indicator style'progressBar', 'segmented', or 'numbered'No'progressBar'
previewSchemaBeforeUploadShow expected columns before uploadbooleanNotrue
templateDownloadOffer downloadable template filesTemplateDownloadConfigNo
saveSessionPersist session for resuming interrupted importsbooleanNo
localeLocale string overrides (see Localization)DeepPartial<ExpressCSVLocaleInput>No
disableStatusStepSkip the success/error status screenbooleanNo

Return Values

PropertyDescriptionType
openOpens the widget. Requires at least one of onData or webhook.(options: OpenOptions<T>) => void
closeCloses the widget() => void
restartResets and reopens the widget for a new import() => void
widgetStateCurrent widget state (reactive)WidgetState
isOpentrue while the widget is openboolean
isReadytrue when the widget is initialized and ready to openboolean
canRestarttrue when the widget can be restartedboolean
lastErrorMost recent error, or nullError or null
connectionStatusIframe connection statusstring

open(options)

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

OptionDescriptionTypeRequired
onDataCallback for each chunk. Call next() to receive the next chunk.(chunk: RecordsChunk<T>, next: () => void) => void or Promise<void>*
webhookWebhook endpoint for server-side delivery (see Webhooks)WebhookConfig*
chunkSizeRecords per chunk (default: 1000)numberNo
onCompleteCalled when all chunks have been processed() => voidNo
onCancelCalled when the user cancels the import() => voidNo
onErrorCalled when an error occurs(error: Error) => voidNo
onWidgetOpenCalled when the widget opens() => voidNo
onWidgetCloseCalled when the widget closes(reason: string) => voidNo
onStepChangeCalled when the wizard step changes(stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => voidNo

* At least one of onData or webhook is required.


RecordsChunk<T>

interface RecordsChunk<T> {
  records: T[];
  totalChunks: number;
  currentChunkIndex: number;
  totalRecords: number;
}
PropertyDescriptionType
recordsValidated records for this chunk, typed from your schemaT[]
totalChunksTotal number of chunks in the deliverynumber
currentChunkIndex0-based index of the current chunknumber
totalRecordsTotal records across all chunksnumber

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)