I have an upload button to import only CSV files to my Reactjs application. I can successfully upload the data(CSV) using React file reader but now I want to show the CSV data it into a table. I think this could help me but I cannot understand how to use it https://github.com/marudhupandiyang/react-csv-to-table here. Below is my code:
import React, { Component } from 'react';
import ReactFileReader from 'react-file-reader';
import { CsvToHtmlTable } from 'react-csv-to-table';
import './App.css';
class App extends Component {
constructor(props){
super(props);
this.state = {
csvData: ''
};
}
handleFiles = files => {
var reader = new FileReader();
reader.onload = function(e) {
// Use reader.result
this.setState({
csvData: reader.result
})
}
reader.readAsText(files[0]);
}
render() {
return (
<div>
<ReactFileReader handleFiles={this.handleFiles} fileTypes={'.csv'}>
<button className='btn'>Upload</button>
</ReactFileReader>
<CsvToHtmlTable
data={this.state.csvData}
csvDelimiter=","
tableClassName="table table-striped table-hover"
/>
</div>
);
}
}
export default App;
please help. It's very important to me.
CsvToHtmlTablecomponent.