Get started with react-table CDN

MIT licensed

React-table is a popular library for building dynamic, user-interactive tables in React applications.

Tags:
  • react
  • table
  • react-table
  • datagrid

Stable version

Copied!

How to start using react-table CDN


import React from 'react';
import { useTable } from 'react-table';

const data = [
  {
    id: 1,
    name: 'Sabina',
    age: 23,
    city: 'New York'
  },
  {
    id: 2,
    name: 'Leo',
    age: 35,
    city: 'San Francisco'
  },
  {
    id: 3,
    name: 'Anna',
    age: 28,
    city: 'Chicago'
  }
];

function Table() {
  const columns = React.useMemo(
    () => [
      {
        Header: 'Name',
        accessor: 'name'
      },
      {
        Header: 'Age',
        accessor: 'age'
      },
      {
        Header: 'City',
        accessor: 'city'
      }
    ],
    []
  );

  const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    rows,
    prepareRow
  } = useTable({ columns, data });

  return (
    <table {...getTableProps()}>
      <thead>
        {headerGroups.map(headerGroup => (
          <tr {...headerGroup.getHeaderGroupProps()}>
            {headerGroup.headers.map(column => (
              <th {...column.getHeaderProps()}>{column.render('Header')}</th>
            ))}
          </tr>
        ))}
      </thead>
      <tbody {...getTableBodyProps()}>
        {rows.map(row => {
          prepareRow(row);
          return (
            <tr {...row.getRowProps()}>
              {row.cells.map(cell => (
                <td {...cell.getCellProps()}>{cell.render('Cell')}</td>
              ))}
            </tr>
          );
        })}
      </tbody>
    </table>
  );
}

export default Table;

All versions