1

I am trying react-csv. https://www.npmjs.com/package/react-csv

This is data:

users = [
{firtstname: 'Ahmed', lastname: 'Tomi' , email: '[email protected]'},
{firtstname: 'Raed', lastname: 'Labes' , email: '[email protected]'},
{firstname: 'Yezzi', lastname: 'Min l3b', email: '[email protected]'}
];

Data for react-csv:

<CSVLink data={this.props.users} >Download me</CSVLink>

Then, how do I get only lastname and email for csv. I try to do like this but something went wrong.

handleExport = () => {
this.state.exportData = this.props.users.map((user, index) => (
user.lastname + user.email
));
}

Thanks.

2 Answers 2

3

Two choices. Either map your data so it only contains what you need. Something like

<CSVLink data={this.props.users.map(x => ({ lastname: x.lastname, email: x.email }))}>Download me</CSVLink>

Or, use the headers prop to define the data you want

headers = [
  { label: 'Last Name', key: 'lastname' },
  { label: 'Email', key: 'email' }
];

<CSVLink data={this.props.users} headers={headers}>Download me</CSVLink>
Sign up to request clarification or add additional context in comments.

Comments

0
<CSVLink data={this.state.exportData} >Download me</CSVLink>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.