Skip to main content

Hook-based Importer (useDataImporter)

Advanced
info

This feature is available for React only.

Concept

DescriptionuseDataImporter is a hook-based alternative to the <DataImporter /> component. Use it when you want your own upload button or need to hide the importer until the user clicks it.

Return values

PropertyDescription
refAttach to a container element (<div ref={ref} />). Must be a callback ref, not an object ref.
openOpens the importer UI. The container stays hidden until open() is called.
isReadytrue when the license is verified and the importer is ready for user interaction.
isUploadingtrue while an upload is in progress.
errorContains type and message when an error occurs. null when there is no error.
reloadReloads this instance with a new session ID.

Basic example

import { useDataImporter } from "@ingestro/importer-react";

function ImportButton() {
const { ref, open, isReady, isUploading, error } = useDataImporter({
licenseKey: "Your License Key",
settings: {
identifier: "product-data",
developerMode: true,
columns: [
{ label: "Product ID", key: "product_id" },
{ label: "Article Name", key: "article_name" },
],
},
onUploadSuccess: () => analytics.track("file-upload-success"),
onUploadError: ({ type, message }) => analytics.track("file-upload-error", { type, message }),
});

return (
<>
<div ref={ref} />
<button onClick={open} disabled={!isReady || isUploading}>
Upload file
</button>
{error ? <p>{error.message}</p> : null}
</>
);
}