import React from 'react' import styled from 'styled-components' import { useTable, usePagination } from 'react-table' import makeData from './makeData' const Styles = styled.div` padding: 1rem; table { border-spacing: 0; border: 1px solid black; tr { :last-child { td { border-bottom: 0; } } } th, td { margin: 0; padding: 0.5rem; border-bottom: 1px solid black; border-right: 1px solid black; :last-child { border-right: 0; } } } .pagination { padding: 0.5rem; } ` function Table({ columns, data }) { // Use the state and functions returned from useTable to build your UI const { getTableProps, headerGroups, prepareRow, page, // Instead of using 'rows', we'll use page, // which has only the rows for the active page // The rest of these things are super handy, too ;) canPreviousPage, canNextPage, pageOptions, pageCount, gotoPage, nextPage, previousPage, setPageSize, state: [{ pageIndex, pageSize }], } = useTable( { columns, data, }, usePagination ) // Render the UI for your table return ( <>
        
          {JSON.stringify(
            {
              pageIndex,
              pageSize,
              pageCount,
              canNextPage,
              canPreviousPage,
            },
            null,
            2
          )}
        
      
{headerGroups.map(headerGroup => ( {headerGroup.headers.map(column => ( ))} ))} {page.map( (row, i) => prepareRow(row) || ( {row.cells.map(cell => { return ( ) })} ) )}
{column.render('Header')}
{cell.render('Cell')}
{/* Pagination can be built however you'd like. This is just a very basic UI implementation: */}
{' '} {' '} {' '} {' '} Page{' '} {pageIndex + 1} of {pageOptions.length} {' '} | Go to page:{' '} { const page = e.target.value ? Number(e.target.value) - 1 : 0 gotoPage(page) }} style={{ width: '100px' }} /> {' '}
) } function App() { const columns = React.useMemo( () => [ { Header: 'Name', columns: [ { Header: 'First Name', accessor: 'firstName', }, { Header: 'Last Name', accessor: 'lastName', }, ], }, { Header: 'Info', columns: [ { Header: 'Age', accessor: 'age', }, { Header: 'Visits', accessor: 'visits', }, { Header: 'Status', accessor: 'status', }, { Header: 'Profile Progress', accessor: 'progress', }, ], }, ], [] ) const data = React.useMemo(() => makeData(100000), []) return ( ) } export default App