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:
- Serialize the current configuration.
- Resolve the main product from the store (throws if none is found).
- Create a snapshot.
- Request design generation.
- Poll until the generation process is ready (cancellable via
abort()). - 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.