react-file-preview-latest

1.0.3 • Public • Published

react-file-preview-latest

React component to render and preview images, pdf and text files via file object or web url

Example

alt text

import React, { Component } from "react";
import FilePreview from "react-file-preview-latest";

class App extends Component {
  constructor() {
    super();
    this.state = {
      file: null,
    };
  }
  
  onError = (err) => console.log("Error:", err); // Write your own logic

  render() {
    return (
      <FilePreview
        type={"file"}
        file={this.state.file}
        onError={this.onError}
      />
    );
  }
}

export default App;

Install

npm install react-file-preview-latest

Props

type

It can be either file or url.


file

The file object of input[type="file"] element which needs to be previewed.


url

The url which needs to be previewed.


onError

A callback function to get detailed error.

License

MIT

Package Sidebar

Install

npm i react-file-preview-latest

Weekly Downloads

428

Version

1.0.3

License

ISC

Unpacked Size

196 kB

Total Files

8

Last publish

Collaborators

  • syadav214