Open this example in the interactive library
Source code
// app/books/page.tsx
export default function BorrowingShareTable() {
const books = [
{ slug: "ink", name: "Print in Ink", year: 2020, genre: "Art", loans: 14 },
{ slug: "type", name: "Type Design", year: 2024, genre: "Design", loans: 8 },
{ slug: "paper", name: "Paper Works", year: 2024, genre: "Art", loans: 22 },
];
const total = books.reduce((s, b) => s + b.loans, 0);
return (
<table>
<caption>Share of borrowing</caption>
<tbody>
{books.map((b) => (
<tr key={b.slug}>
<th>{b.name}</th>
<td>{Math.round((100 * b.loans) / total)}%</td>
</tr>
))}
</tbody>
</table>
);
}
