项目作者: VitorLuizC

项目描述 :
React Hook to create and revoke URL for any instance of `File`, `Blob` or `MediaSource`.
高级语言: TypeScript
项目地址: git://github.com/VitorLuizC/use-object-url.git
创建时间: 2019-09-01T17:47:30Z
项目社区:https://github.com/VitorLuizC/use-object-url

开源协议:MIT License

下载


useObjectURL

Build Status
License
Library minified size
Library minified + gzipped size

React Hook that receives an instance of File, Blob or MediaSource and creates an URL representing it. It releases URL when component unmount or parameter changes.

  1. import useObjectURL from 'use-object-url';
  2. const DownloadFileLink = ({ file, filename }) => {
  3. const { objectURL } = useObjectURL(file);
  4. return (
  5. <a href={objectURL} target="_blank" download={filename}>
  6. Download
  7. </a>
  8. );
  9. };

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

  1. npm install use-object-url --save
  2. # For Yarn, use the command below.
  3. yarn add use-object-url

Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

  1. <!-- For UNPKG use the code below. -->
  2. <script src="https://unpkg.com/use-object-url"></script>
  3. <!-- For JSDelivr use the code below. -->
  4. <script src="https://cdn.jsdelivr.net/npm/use-object-url"></script>
  5. <script>
  6. function PreviewImage(props) {
  7. // UMD module is exposed through the "useObjectURL" function.
  8. var { objectURL } = useObjectURL(props.uploadedImage);
  9. return React.createElement('img', {
  10. src: objectURL,
  11. alt: 'Uploaded image',
  12. title: 'Preview of uploaded image.'
  13. });
  14. }
  15. </script>

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.