I am trying to convert and then download an array of objects. my conversion looks like
const convertToCsv = (objects) => {
var res = objects;
var data = new Blob([res], { type: "text/csv" });
var csvURL = URL.createObjectURL(data);
return csvURL;
};
which results in a blob URL
and my data to download looks like this
[
0: {sid: 31, name: "jkk", email: "kkjd@abc.com", updated_at: "2021-09-19T17:17:22.099363+00:00"}
1: {sid: 32, name: "jak", email: "kkjd@abc.com", updated_at: "2021-09-19T17:17:22.099363+00:00"}
]
my download link looks like this
<a href={downloadArray.length ? convertToCsv(downloadArray) : null} target="_blank" download="filename.csv">
download selected
</a>
my CSV file looks like this
[object Object] [object Object]
however, when I target only the email or name etc it downloads the data correctly. I know it will be something small that I am missing!
As always any help is greatly appreciated.
EDIT:
I have created a sandbox which reproduces the issue https://codesandbox.io/s/elastic-night-c98et?file=/src/App.js