A React library to render a component that helps in json to csv conversion.
Install the component using NPM:
$ npm install --save react-json-csv
Or YARN;
$ yarn add react-json-csv
import {
JsonToCsv,
useJsonToCsv
} from 'react-json-csv';
Converts json to csv file (.csv format) and downloads it
const filename = 'Csv-file',
fields = {
"index": "Index",
"guid": "GUID"
},
style = {
padding: "5px"
},
data = [
{ index: 0, guid: 'asdf231234'},
{ index: 1, guid: 'wetr2343af'}
],
text = "Convert Json to Csv";
<JsonToCsv
data={data}
filename={filename}
fields={fields}
style={style}
text={text}
/>
const { saveAsCsv } = useJsonToCsv();
<button onClick={saveAsCsv({ data, fields, filename })}>
useJsonToCsv
</button>