Control tasks with useEazip()
Start ZIP downloads, read the current React task, and share defaults without duplicating engine state.
useEazip() connects a component to the current Eazip task and its actions. Use
it whether you render <EazipTray /> or your own interface.
Start a download
import { useEazip } from '@eazip/react';
function DownloadButton({ files }: { files: File[] }) {
const zip = useEazip();
return (
<button
disabled={zip.isBusy}
onClick={() =>
zip.download({
files,
zipName: 'export.zip',
})
}
>
Download as ZIP
</button>
);
}download() starts the task and returns its ID immediately. Processing and
network failures appear on task; they are not asynchronous exceptions from
the call.
Validate an optional selection first
An empty or unsupported files value fails synchronously. Disable the action
or validate the selection when an empty list is a normal UI state.
Read the current task
| State | Meaning | Typical UI |
|---|---|---|
processing | The Local or Cloud job is running | Progress or an indeterminate status, plus cancel |
completed | All output is ready | Download action |
partial | Output is ready with skipped files | Download plus a skipped-count notice |
failed | No usable output was produced | Error and retry when canRetry is true |
expired | Cloud output is no longer available | Start a new export |
isBusy is the short form of checking for a processing task. Use task when
the interface needs progress, ZIP parts, errors, or expiry.
Choose the session path
- Local:
download({ files })runs in the browser. - Frontend-created Cloud: add
strategy: 'cloud',publicKey, and URL sources. - Backend-created Cloud: pass
createSessioninstead offilesandpublicKey.
See Backend-created sessions for the trusted server boundary.
Share defaults when needed
No provider is required. Add EazipProvider when several components need the
same defaults or a test needs isolated state:
import { EazipProvider } from '@eazip/react';
<EazipProvider
config={{
strategy: 'cloud',
publicKey: 'pk_ez_...',
defaults: { zipName: 'export.zip' },
}}
>
<App />
</EazipProvider>Per-download options take precedence over provider defaults. See the React Reference for every action, option, task field, and provider setting.