Answer the question
In order to leave comments, you need to log in
React - csv not seeing my array?
Hello, please help me to solve the problem:
Here is my code:
import React from "react";
import axios from 'axios';
import { CSVLink } from "react-csv";
export default class Bookkeepings extends React.Component {
constructor(props) {
super(props);
this.state = {
rows: []
}
componentDidMount () {
axios.get(API+"referenceData", {
})
.then(res => {
this.setState({
rows: res.data
})
console.log(rows);
})
}
render () {
const { rows } =this.state
return (
<div className="container">
<CSVLink
data={rows}
separator={";"}
filename={"my-file.csv"}
className="btn btn-primary"
target="_blank"
>
Download me
</CSVLink>)
}
}
(3) [{…}, {…}, {…}]
0: {ownerKey: "test_owner", accountNumber: "54325672098734"}
1: {ownerKey: "test_owner", accountNumber: "82039564645380"}
2: {ownerKey: "test_owner2", accountNumber: "92637479276455"}
length: 3
__proto__: Array(0)
const rows = [
{ firstname: 'Ahmed', lastname: 9, email: '[email protected]' }
];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question