@thestartupfactory/file-progress-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

File Download Hook

This library offers a useDownloadFile hook which tracks the progress of the file download. In order for the download % to be determined then the file size needs to be known when mutate is called.

Installation

npm install @thestartupfactory/file-progress-hook

Example hook usage

const [downloadProgress, setDownloadProgress] = useState<ProgressState>({
  state: 'awaiting',
});

const downloadFile = useDownloadFile({
  errorMessage: (fileName) => `Failed to download ${fileName}`,
  downloadingMessage: (fileName) => `Downloading ${fileName}`,
  completeMessage: (fileName) => `${fileName} successfully downloaded`,
});

downloadFile.mutate({
  setProgress,
  url: 'https://localhost:4200/file',
  fileName: 'myImage.png',
  fileSize: 154242, // in bytes
});

Building

Run nx build open-file-download-hook to build the library.

Troubleshooting

When using the hook exported by this library it is common to get an error similar to this:

Error
No QueryClient set, use QueryClientProvider to set one
Call Stack
 ...

A solution to this issue is to set up the correct path resolution in your tsconfig.json. This ensures that TypeScript recognizes the package correctly, which can help eliminate related issues:

{
  "compilerOptions": {
    "paths": {
      "@tanstack/react-query": ["./node_modules/@tanstack/react-query"],
    }
  },
}

Readme

Keywords

none

Package Sidebar

Install

npm i @thestartupfactory/file-progress-hook

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

22 kB

Total Files

19

Last publish

Collaborators

  • ericc_thestartupfactory.tech