Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 512 Bytes

use-download.md

File metadata and controls

27 lines (20 loc) · 512 Bytes

useDownload

Returns a function that can be called to download a file to a user.

Example

import * as React from "react";
import { useDownload } from "@casperiv/useful/hooks/useDownload";

const Component = () => {
  const download = useDownload();

  function handleDownload() {
    const json = {
      hello: "world",
    };

    download({
      filname: "myfile.json",
      data: JSON.stringify(json, null, 2),
    });
  }

  return <button onClick={handleDownload}>Click me!</button>;
};