Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created December 4, 2017 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/415c53ec7475ebb066373983c93ccc1e to your computer and use it in GitHub Desktop.
Save dance2die/415c53ec7475ebb066373983c93ccc1e to your computer and use it in GitHub Desktop.
import React from "react";
import shortid from "shortid";
const TableView = ({ data }) => {
const { labels, datasets } = data;
const headers = datasets.map(set => (
<th key={shortid.generate()}>{set.title}</th>
));
const rows = labels.map((label, i) => {
return (
<tr key={shortid.generate()}>
<td key={shortid.generate()}>{label}</td>
{datasets.map(set => <td key={shortid.generate()}>{set.values[i]}</td>)}
</tr>
);
});
return (
<table>
<thead>
<tr>
<th key={shortid.generate()}>Labels</th>
{headers}
</tr>
</thead>
<tbody>{rows}</tbody>
</table>
);
};
export default TableView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment