How to read a .json file
Norfeldt opened this issue · comments
Lasse Nørfeldt commented
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
Lasse Nørfeldt commented
Stackoverflow solved my problem.
https://stackoverflow.com/questions/49776193/react-open-json-file-via-dialog-and-read-content