Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codesmith-99/react-file-preview

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codesmith-99/react-file-preview

The url previewer is built using native html elements for previewing url of files of the following type

  • 1.0.30
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-file-preview

The url previewer is built using native html elements for previewing url of files of the following type

  • csv files
  • text files
  • pdf files
  • html files
  • image files (supported by the browser)
  • audio files (supported by the browser)
  • video files (supported by the browser)
  • docx, xlsx, pptx files

Installation

npm i @codesmith-99/react-file-preview

Usage

Currently, the file supports only urls, in the future hopefully it can be extended to files also.

Basic Usage

import React, { useState } from 'react'
import FileViewer from '@codesmith-99/react-file-preview'

export default function Demo() {
  const [file, setFile] = useState<string>('')
  const [mimeType, setMimeType] = useState<string>()
  const [name, setName] = useState<string>('image.jpg')

  return (
    <>
      <div>
        <label>File url</label>
        <br />
        <input type='text' onChange={(e) => setFile(e.target.value)} />
      </div>
      <div>
        <label>File mimeType</label>
        <br />
        <input type='text' onChange={(e) => setMimeType(e.target.value)} value={mimeType} />
      </div>
      <div>
        <label>File name</label>
        <br />
        <input type='text' onChange={(e) => setName(e.target.value)} value={name} />
      </div>
      <div
        style={{
          height: '500px',
          width: '500px',
        }}
      >
        <FileViewer
          loader={undefined}
          mimeType={mimeType}
          src={file}
          onError={(e) => {
            console.log(e)
          }}
          fileName={name}
        />
      </div>
    </>
  )
}

FileViewer Props

Prop nameTypeDescription
srcstringThe url of the file to be previewed
mimetypestring (optional)Used to specify the mimetype of the file and determine how to preview the url, alternatively filename can be used
filenamestring (optional)The file extension is used to specify the mimetype of the file and determine how to preview the url, alternatively mimetype can be used
loaderReactNode (optional)A loader to replace the default loader used by the project
onError(e: any) => void (optional)A callback that can be used to detect if an error has occurred in the loading of the files

Keywords

FAQs

Package last updated on 05 May 2023

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