mother / react-files

A file input (dropzone) management component for React

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to read a .json file

Norfeldt opened this issue · comments

This is most likely a newbie question, but how do I read the content of the file that I load?

Would like to load a .json file and assign it to a variable or dump it into state. This is my current (not working) code prototype:

import React, { Component } from 'react'
import Files from 'react-files'

class LoadFile extends Component {
  render() {
    return (
      <div className="files">
        <Files
          className="files-dropzone"
          onChange={file => {
            console.log(JSON.stringify(file))
          }}
          onError={err => console.log(err)}
          accepts={['.json']}
          multiple
          maxFiles={3}
          maxFileSize={10000000}
          minFileSize={0}
          clickable
        >
          Drop files here or click to upload
        </Files>
      </div>
    )
  }
}

export default LoadFile