const itemsArray = [ { itemId: 1, itemRef: "Item 001" }, { itemId: 2, itemRef: "Item 002" }, { itemId: 3, itemRef: "Item 003" } ]; DEV Community How to Export and Download CSV and JSON Files in React
const downloadCSV = (data) => { const csvString = convertToCSV(data); const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'export.csv'); document.body.appendChild(link); link.click(); document.body.removeChild(link); }; Use code with caution. Convert an array of objects to CSV string in JavaScript react download array as csv
import { CSVLink } from "react-csv"; const MyComponent = () => { const data = [ { firstname: "Ahmed", lastname: "Tomi", email: "ah@smurfs.com" }, { firstname: "Raul", lastname: "Gomez", email: "rl@smurfs.com" }, ]; const headers = [ { label: "First Name", key: "firstname" }, { label: "Last Name", key: "lastname" }, { label: "Email", key: "email" }, ]; return ( Download Me ); }; Use code with caution. const itemsArray = [ { itemId: 1, itemRef: