Usage
DownloadTrigger downloads generated content (CSV, JSON, images) as a file without a server request.
It does not render any element, its children is a function that receives:
download– function that starts 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:
Async data
data can be a function that returns the content or a promise that resolves with it.
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.
Without onError, the error is rethrown:
Custom trigger
Children can return any element: a button, an action icon, a menu item or your own component.
Call download from its 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.