Express CSV Logo

Importer SDK

useExpressCSV(options)

function useExpressCSV<TSchema>(
  options: UseExpressCSVOptions<TSchema>
): {
  open: (options: OpenOptions<Infer<TSchema>>) => void;
  importerState: ImporterState;
  isInitialising: boolean;
  isOpen: boolean;
};

Options

OptionDescriptionTypeRequiredDefault
schemaSchema definition created with x.row()SchemaYes
getSessionTokenAsync callback that asks your backend for a short-lived import session token() => Promise<string>Yes
importIdentifierUnique identifier for this import typestringYes
titleTitle shown in the importer headerstringNo
preloadPreload the importer 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 importerstringNo
fontsCustom font sourcesRecord<string, ECSVFontSource>No
stepDisplayStep indicator style'progressBar', 'segmented', or 'numbered'No'progressBar'
previewSchemaBeforeUploadShow expected columns before uploadbooleanNotrue
columnMatchingConfigure managed column matching or provide a custom matcher{ type: "managed"; exact?: boolean; caseInsensitive?: boolean; normalized?: boolean; inference?: boolean } | { type: "custom"; match: (...) => Promise<...> }Noundefined
promptedEditsEnable managed prompted edits or provide a custom edit handler{ type: "managed" } | { type: "custom"; edit: (...) => Promise<...> }Noundefined
templateDownloadOffer downloadable template filesTemplateDownloadOptions<TSchema>No
sessionRecoveryEnable Recovered sessions with either local recovery or a custom adapter implementing get, set, and removeSessionRecoveryOptionsNo
localeLocale string overrides (see Localization)DeepPartial<ExpressCSVLocaleInput>No
disableStatusStepSkip the success/error status screenbooleanNo

Return Values

PropertyDescriptionType
openOpens the importer. Requires onData for delivery.(options: OpenOptions<T>) => void
importerStateCurrent importer lifecycle state (reactive)ImporterState
isInitialisingtrue while the importer is initializing or openingboolean
isOpentrue while the importer is openboolean

open(options)

Options passed to open().

OptionDescriptionTypeRequired
onDataCallback for each chunk. Call next() after your backend accepts the current chunk.(chunk: RecordsChunk<T>, next: () => void) => void or Promise<void>Yes
chunkSizeRecords per chunk (default: 1000)numberNo
onCompleteCalled when all chunks have been processed(context: { sessionId: string }) => voidNo
onCancelCalled when the user cancels the import(context: { sessionId: string }) => voidNo
onErrorCalled when an error occurs(error: Error, context: { sessionId: string }) => voidNo
onImporterOpenCalled when the importer opens() => voidNo
onImporterCloseCalled when the importer closes`(reason: 'user_close''cancel'
onStepChangeCalled when the wizard step changes(stepId: ExpressCSVStep, previousStepId?: ExpressCSVStep) => voidNo

RecordsChunk<T>

interface RecordsChunk<T> {
  records: T[];
  totalChunks: number;
  currentChunkIndex: number;
  totalRecords: number;
  sessionId: string;
  chunkIdempotencyKey: string;
}
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
sessionIdGenerated session ID for the current import runstring
chunkIdempotencyKeyStable per-chunk idempotency keystring

ImporterState

The importer moves through these states during its lifecycle:

StateDescription
UNINITIALIZEDInitial state before the importer iframe is created
INITIALIZINGIframe is loading and establishing a connection
READYImporter is loaded, preloaded, and ready to be opened
OPENINGopen() has been called; creating an import session
OPENImporter is visible and the user is interacting with it
CLOSINGImporter is in the process of closing
RESETTINGImporter is resetting for a new import
ERRORAn error occurred (check lastError)
DESTROYEDImporter 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 importer iframe is created immediately and loads in the background. This means open() displays the importer 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 importer 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
SessionRecoveryOptionsRecovered sessions configuration
LocalSessionRecoveryOptionsBuilt-in browser recovery configuration
CustomSessionRecoveryOptionsCustom recovery adapter configuration
SessionRecoveryKeyOpaque key generated for a recovered session lookup
RecoveredSessionRecovered importer session payload wrapper
RecoveredSessionDataRecovered row data and column keys
ColumnMatchingFnCustom column matching handler type
ColumnMatchingParamsInput passed to a custom column matching handler
ColumnMatchingResultResult returned by a custom column matching handler
PromptedEditsFnCustom prompted edits handler type
PromptedEditsParamsInput passed to a custom prompted edits handler
PromptedEditsResultResult returned by a custom prompted edits handler
ECSVThemeTheme variable overrides (single or dual-mode)
ColorModePref'light', 'dark', or 'system'
ECSVFontSourceFont source (Google or custom URL)
TailwindThemeVarsTheme variable names
ImporterStateImporter lifecycle state enum
ImporterModeImporter preload 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)