react-table/docs/api
Tanner Linsley ddfa0fa227 Death of the path, fix some hooks, fix selectedRows
- Fixed an issue where dependency hooks were not being reduced properly, thus the table would rerender unnecessarily
- Renamed `toggleRowSelectedAll` to `toggleAllRowsSelected`. Duh...
- Added an `indeterminate` boolean prop to the default props for row selection toggle prop getters
- Renamed `selectedRowPaths` to `selectedRowIds`, which also no longer contains paths, but row IDs
- Grouped or nested row selection actions and state are now derived, instead of tracked in state.
- Rows now have a new property called `id`, which existed before and was derived from the `getRowId` option
- Rows now also have an `isSomeSelected` prop when using the `useRowSelect` hook, which denotes that at least one subRow is selected (if applicable)
- Rows' `path` property has been deprecated in favor of `id`
- Expanded state is now tracked with row IDs instead of paths
- RowState is now tracked with row IDs instead of paths
- `toggleExpandedByPath` has been renamed to `toggleExpandedById`, and thus accepts a row ID now, instead of a row path
2019-12-10 23:04:34 -07:00
..
README.md docs(docs/api/readme.md): fix to useTable link that was giving 404 (#1726) 2019-12-06 10:25:15 -05:00
useAbsoluteLayout.md Add useColumnVisibility as core hook (#1700) 2019-12-05 15:45:25 -05:00
useBlockLayout.md Add useColumnVisibility as core hook (#1700) 2019-12-05 15:45:25 -05:00
useColumnOrder.md Add useColumnVisibility as core hook (#1700) 2019-12-05 15:45:25 -05:00
useExpanded.md Death of the path, fix some hooks, fix selectedRows 2019-12-10 23:04:34 -07:00
useFilters.md v7.0.0-rc.3 2019-12-06 16:33:41 -07:00
useGroupBy.md Death of the path, fix some hooks, fix selectedRows 2019-12-10 23:04:34 -07:00
usePagination.md v7.0.0-rc.2 2019-12-06 16:30:08 -07:00
useResizeColumns.md Add useColumnVisibility as core hook (#1700) 2019-12-05 15:45:25 -05:00
useRowSelect.md Death of the path, fix some hooks, fix selectedRows 2019-12-10 23:04:34 -07:00
useRowState.md Death of the path, fix some hooks, fix selectedRows 2019-12-10 23:04:34 -07:00
useSortBy.md v7.0.0-rc.2 2019-12-06 16:30:08 -07:00
useTable.md Death of the path, fix some hooks, fix selectedRows 2019-12-10 23:04:34 -07:00
useTokenPagination.md Add useColumnVisibility as core hook (#1700) 2019-12-05 15:45:25 -05:00

API

React Table uses React Hooks both internally and externally for almost all of its configuration and lifecycle management. Naturally, this is what allows React Table to be headless and lightweight while still having a concise and simple API.

React Table is essentially a compatible collection of custom React hooks:

Hook Usage

useTable is the primary hook used to build a React Table. It serves as the starting point for every option and every plugin hook that React Table supports. The options passed into useTable are supplied to every plugin hook after it in the order they are supplied, eventually resulting in a final instance object that you can use to build your table UI and interact with the table's state.

const instance = useTable(
  {
    data: [...],
    columns: [...],
  },
  useGroupBy,
  useFilters,
  useSortBy,
  useExpanded,
  usePagination
)

The stages of React Table and plugins

  1. useTable is called. A table instance is created.
  2. The instance.state is resolved from either a custom user state or an automatically generated one.
  3. A collection of plugin points is created at instance.hooks.
  4. Each plugin is given the opportunity to add hooks to instance.hook.
  5. As the useTable logic proceeds to run, each plugin hook type is used at a specific point in time with each individual hook function being executed the order it was registered.
  6. The final instance object is returned from useTable, which the developer then uses to construct their table.

This multi-stage process is the secret sauce that allows React Table plugin hooks to work together and compose nicely, while not stepping on each others toes.

To dive deeper into plugins, see Plugins](TODO) and the [Plugin Guide

Plugin Hook Order & Consistency

The order and usage of plugin hooks must follow The Laws of Hooks, just like any other custom hook. They must always be unconditionally called in the same order.

NOTE: In the event that you want to programmatically enable or disable plugin hooks, most of them provide options to disable their functionality, eg. options.disableSortBy

Option Memoization

React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you pass to useTable should be memoized either via React.useMemo (for objects) or React.useCallback (for functions).