I'm trying to export data as a csv in a react app without a library. My code looks like so:
const download = () => {
const dummyData = 'rahul,delhi,accountsdept\n';
const csvContent = `data:text/csv;charset=utf-8,${dummyData}`;
const encodedURI = encodeURI(csvContent);
window.open(encodedURI);
}
And then I have a button with this download function as an onclick.
<button onClick={download}>
Generate Vehicle Offer Prices
</button>
This is supposed to work in vanilla javascript, is there a reason it doesn't work in react?
Here's a sandbox with the code not working in react sandbox
Here's a link with it working in vanilla js vanilla