Skip to main content

useDownloadDesign

Use useDownloadDesign to let a shopper download a rendered file (a PDF by default) of their current configuration. It returns a DownloadDesignController that snapshots the configuration, requests generation on the backend, polls until the file is ready, and triggers the download.

Getting the controller

import { useDownloadDesign } from "@expivi/product-configurator";

const controller = useDownloadDesign(configurator);

Example: download the current design

const controller = useDownloadDesign(configurator);

// Reflect progress in your UI
const unsubscribe = controller.subscribeBusy(busy => {
renderSpinner(busy);
});

// Kick off the full download flow (resolves when done or aborted)
await controller.download();

// Optionally cancel while it is still running
// controller.abort();

unsubscribe();

API

isBusy

Getter that returns whether a download flow is currently running. download() is a no-op while busy.

download()

Runs the full download flow:

  1. Serialize the current configuration.
  2. Resolve the main product from the store (throws if none is found).
  3. Create a snapshot.
  4. Request design generation.
  5. Poll until the generation process is ready (cancellable via abort()).
  6. Download the resulting file (falls back to the filename design.pdf).

If the flow fails, an error message is pushed through useMessages(configurator). An abort is swallowed silently.

abort()

Cancels an in-progress poll/download flow through its AbortController.

subscribeBusy(callback)

Subscribes to busy-state changes. callback receives the new boolean value. Returns an unsubscribe function.