{"id":21521591,"url":"https://github.com/zzarcon/react-preview-file","last_synced_at":"2025-04-09T22:22:21.954Z","repository":{"id":57342672,"uuid":"123508771","full_name":"zzarcon/react-preview-file","owner":"zzarcon","description":"Efficient image preview rendering from files :zap:","archived":false,"fork":false,"pushed_at":"2018-08-27T09:40:31.000Z","size":171,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T13:19:28.308Z","etag":null,"topics":["createobjecturl","file","filereader","image","preview","react"],"latest_commit_sha":null,"homepage":"https://zzarcon.github.io/react-preview-file","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zzarcon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-02T00:27:15.000Z","updated_at":"2025-02-11T15:50:16.000Z","dependencies_parsed_at":"2022-09-16T02:50:36.249Z","dependency_job_id":null,"html_url":"https://github.com/zzarcon/react-preview-file","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzarcon%2Freact-preview-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzarcon%2Freact-preview-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzarcon%2Freact-preview-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzarcon%2Freact-preview-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zzarcon","download_url":"https://codeload.github.com/zzarcon/react-preview-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248120490,"owners_count":21050956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["createobjecturl","file","filereader","image","preview","react"],"created_at":"2024-11-24T01:07:38.946Z","updated_at":"2025-04-09T22:22:21.930Z","avatar_url":"https://github.com/zzarcon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-preview-file [![Build Status](https://travis-ci.org/zzarcon/react-preview-file.svg?branch=master)](https://travis-ci.org/zzarcon/react-preview-file)\n\u003e Efficient way of rendering an image preview from a File\n\n# Installation\n\n```\n$ yarn add react-preview-file\n```\n\n# Usage\n\n**simple**\n\n```javascript\nimport FilePreview from 'react-preview-file';\n\nrender() {\n  const file = new File(['someBase64'], 'me.png');\n  return (\n    \u003cFilePreview file={file}\u003e\n      {(preview) =\u003e \u003cimg src={preview} /\u003e}\n    \u003c/FilePreview\u003e\n  )\n}\n\n```\n\n**full**\n\n```javascript\nimport FilePreview from 'react-preview-file';\n\nclass App extends React.Component {\n  onInputChange = e =\u003e {\n    const { currentTarget: { files } } = e;\n\n    this.setState({files[0]});\n  }\n\n  render() {\n    const {file} = this.state;\n\n    return (\n      \u003cdiv\u003e\n        \u003cinput type=\"file\" onChange={this.onChange} /\u003e\n        \u003cFilePreview file={file}\u003e\n          {(preview) =\u003e \u003cimg src={preview} /\u003e}\n        \u003c/FilePreview\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n\n```\n\n# API\n\n* **file**: [File](https://developer.mozilla.org/en-US/docs/Web/API/File)\n* **children**: (preview: string) =\u003e ReactNode\n\n# Motivation\n- Avoid multiple re-renders: **FilePreview** uses [URL.createObjectURL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL) instead of [FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader), the first one happens asynchronously and avoids dealing with state and multiple re-renders 👁\n- Automatically revoke: **FilePreview** takes care for you of [revoke](https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL) the created preview. This makes memory usage as efficient as possible 🔥\n- Efficient preview generation: Not only **createObjectURL** is faster than [FileReader.readAsDataURL](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL) byt it also produces fixed length strings, instead of massive base64 strings ⚡️\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzarcon%2Freact-preview-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzzarcon%2Freact-preview-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzarcon%2Freact-preview-file/lists"}