MCPcopy
hub / github.com/TanStack/table / useReactTable

Function useReactTable

packages/react-table/src/index.tsx:57–94  ·  view source on GitHub ↗
(
  options: TableOptions<TData>,
)

Source from the content-addressed store, hash-verified

55}
56
57export function useReactTable<TData extends RowData>(
58 options: TableOptions<TData>,
59) {
60 // Compose in the generic options to the user options
61 const resolvedOptions: TableOptionsResolved<TData> = {
62 state: {}, // Dummy state
63 onStateChange: () => {}, // noop
64 renderFallbackValue: null,
65 ...options,
66 }
67
68 // Create a new table and store it in state
69 const [tableRef] = React.useState(() => ({
70 current: createTable<TData>(resolvedOptions),
71 }))
72
73 // By default, manage table state here using the table's initial state
74 const [state, setState] = React.useState(() => tableRef.current.initialState)
75
76 // Compose the default state above with any user state. This will allow the user
77 // to only control a subset of the state if desired.
78 tableRef.current.setOptions((prev) => ({
79 ...prev,
80 ...options,
81 state: {
82 ...state,
83 ...options.state,
84 },
85 // Similarly, we'll maintain both our internal state and any user-provided
86 // state.
87 onStateChange: (updater) => {
88 setState(updater)
89 options.onStateChange?.(updater)
90 },
91 }))
92
93 return tableRef.current
94}

Callers 15

TableFunction · 0.90
core.test.tsxFile · 0.90
TableComponentFunction · 0.90
TableFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
TableFunction · 0.90

Calls 1

createTableFunction · 0.90

Tested by 3

TableFunction · 0.72
TableComponentFunction · 0.72
TableFunction · 0.72