Skip to content

Instantly share code, notes, and snippets.

@granolocks
Created July 16, 2020 17:47
Show Gist options
  • Save granolocks/d58c86dead22c9d7ec98b325d19eecc7 to your computer and use it in GitHub Desktop.
Save granolocks/d58c86dead22c9d7ec98b325d19eecc7 to your computer and use it in GitHub Desktop.
import React from 'react';
const DumbTable = ({ data }) => {
if (!data || data.length === 0) {
return <>No data!</>
}
const columns = Object.keys(data[0])
return (
<table>
<thead>
<tr>
{columns.map(x => (
<th key={JSON.stringify(x)} style={{ padding: '.5em' }}>
{x}
</th>
))}
</tr>
</thead>
<tbody>
{data.map(y => (
<tr key={JSON.stringify(y)}>
{columns.map(x => (
<td key={JSON.stringify(x)} style={{ padding: '.5em' }}>
{y[x]}
</td>
))}
</tr>
))}
</tbody>
</table>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment