Socket
Socket
Sign inDemoInstall

react-html-to-image

Package Overview
Dependencies
7
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-html-to-image

TODO


Version published
Weekly downloads
27
increased by35%
Maintainers
1
Install size
3.94 MB
Created
Weekly downloads
 

Readme

Source

react-html-to-image

A simple React hook to download your HTML markup as a .jpg image.

Installation

Using yarn:

yarn add react-html-to-image

or with npm:

npm install react-html-to-image

Usage

import { useHtmlToImage } from "react-html-to-image";

export const App = () => {
  const { ref, saveHtmlAsImage } = useHtmlToImage();

  const handleDownloadImage = async () => {
    try {
      await saveHtmlAsImage("your-file-name", {
        quality: 0.7,
      });
    } catch (error) {
      // Handle error.
    }
  };

  return (
    <main>
      <div ref={ref} className="…">
        {/* Your markup */}
      </div>
    
      <button onClick={handleDownloadImage} />
    </main>
  );
};

saveHtmlAsImage accepts two params: saveHtmlAsImage(fileName, options)

ParamTypeRequiredDefaultDescription
fileNamestringtrueThe file name for the downloaded image.
optionsobjectfalseThe options for saving your downloaded image.
options.qualityobject0.7The desired quality of the image. Default is 0.7

See the example for sample implementation.

Known issues

  • <img /> within display: flex containers do not show in the downloaded image.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update the tests as appropriate.

License

MIT

Keywords

FAQs

Last updated on 27 Jun 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc