DownloadTrigger
Trigger a client-side file download
Source
LLM docs
Docs
Package
Usage
DownloadTrigger downloads generated content (CSV, JSON, images, QR codes) as a file
without a server request. It does not render any element – its children is a function
that receives an object with the following properties:
download– function that must be called to trigger the downloadloading–truewhile an asyncdatafunction is resolving
data can be a string, a Blob or a File. Set mimeType prop when data is a string.
Use fileName prop to set the name of the downloaded file. When fileName is not set
and data is a File, the file name is used.
onDownloadComplete is called when the download is dispatched to the browser, not when the browser
finishes saving the file.
Async data
data can be a function that returns a Blob/string or a promise that resolves with one.
The function is called when the download is triggered. While it is resolving, loading
is true and repeated download calls are ignored:
Error handling
If resolving data or the download fails, the error is passed to onError callback.
If onError is not set, the error is rethrown:
Custom trigger
Children can return any element – a Button, an ActionIcon, a
Menu.Item or your own component. Call the download function from the element onClick
handler:
Accessibility
When the trigger is icon-only, set aria-label to describe the action:
Incompatible with server components
DownloadTrigger is not compatible with React server components because it requires using function as children. To use DownloadTrigger, add "use client;" at the top of the file.