New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-use-downloader

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-downloader

Creates a download handler function and gives progress information

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source
traffic

react-use-downloader

Creates a download handler function with its progress information and cancel ability.

NPM


Table of Contents


Running example

Plain
Example
Preview!

Install

npm install --save react-use-downloader

Usage

import React from "react";
import useDownloader from "react-use-downloader";

export default function App() {
  const {
    size,
    elapsed,
    percentage,
    download,
    cancel,
    error,
    isInProgress
  } = useDownloader();

  const fileUrl = "https://olavoparno.github.io/saywololo/sounds/Wololo1.wav";

  return (
    <div className="App">
      {isInProgress ? (
        <p>Download is in progress</p>
      ) : (
        <p>Download is stopped</p>
      )}
      <button onClick={() => download(fileUrl, "file")}>
        Click to download file
      </button>
      <span> </span>
      <button onClick={() => cancel()}>Cancel</button>
      <p>
        Download size {size} bytes and {percentage}%
      </p>
      <LinearProgress variant="determinate" value={percentage} />
      <p>Elapsed time {elapsed}s</p>
      {error && <p>possible error {JSON.stringify(error)}</p>}
    </div>
  );
}

Documentation

useDownloader() returns:

  • An object with the following keys:

    1. size (size in bytes)
    2. elapsed (in seconds)
    3. percentage (a percentage string)
    4. download (a download function handler)
    • arguments, both as string: {downloadUrl, filename}
    1. cancel (a cancel function)
    2. error (an error object from the fetch request)
    3. isInProgress (a boolean status wether it is downloading or not)
const {
    size,
    elapsed,
    percentage,
    download,
    cancel,
    error,
    isInProgress
  } = useDownloader();

License

react-use-downloader is MIT licensed.


This hook is created using create-react-hook.

FAQs

Package last updated on 22 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc