@tanstack/react-table 8.0.11 → 8.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/react-table/src/index.js +15 -21
- package/build/cjs/react-table/src/index.js.map +1 -1
- package/build/cjs/table-core/build/esm/index.js +567 -671
- package/build/cjs/table-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +579 -686
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +90 -0
- package/build/types/index.d.ts +20 -0
- package/build/umd/index.development.js +580 -689
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +19 -43
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.14",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for React.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"node": ">=12"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
|
-
"build",
|
|
34
|
+
"build/**",
|
|
35
35
|
"src"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/table-core": "8.0.
|
|
38
|
+
"@tanstack/table-core": "8.0.14"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16",
|
package/src/index.tsx
CHANGED
|
@@ -2,15 +2,10 @@ import * as React from 'react'
|
|
|
2
2
|
export * from '@tanstack/table-core'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
createTable,
|
|
6
6
|
TableOptions,
|
|
7
|
-
TableInstance,
|
|
8
|
-
Table,
|
|
9
|
-
TableGenerics,
|
|
10
|
-
createTableFactory,
|
|
11
|
-
Overwrite,
|
|
12
|
-
PartialKeys,
|
|
13
7
|
TableOptionsResolved,
|
|
8
|
+
RowData,
|
|
14
9
|
} from '@tanstack/table-core'
|
|
15
10
|
|
|
16
11
|
export type Renderable<TProps> =
|
|
@@ -18,20 +13,14 @@ export type Renderable<TProps> =
|
|
|
18
13
|
| React.FunctionComponent<TProps>
|
|
19
14
|
| React.Component<TProps>
|
|
20
15
|
|
|
21
|
-
export type Render = <TProps extends {}>(
|
|
22
|
-
Comp: Renderable<TProps>,
|
|
23
|
-
props: TProps
|
|
24
|
-
) => React.ReactNode | JSX.Element
|
|
25
|
-
|
|
26
|
-
export type ReactTableGenerics = Overwrite<
|
|
27
|
-
TableGenerics,
|
|
28
|
-
{ Renderer: Render; Rendered: ReturnType<Render> }
|
|
29
|
-
>
|
|
30
|
-
|
|
31
16
|
//
|
|
32
17
|
|
|
33
|
-
export
|
|
34
|
-
|
|
18
|
+
export function flexRender<TProps extends object>(
|
|
19
|
+
Comp: Renderable<TProps>,
|
|
20
|
+
props: TProps
|
|
21
|
+
): React.ReactNode | JSX.Element {
|
|
22
|
+
return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
|
|
23
|
+
}
|
|
35
24
|
|
|
36
25
|
function isReactComponent(component: unknown): component is React.FC {
|
|
37
26
|
return (
|
|
@@ -59,41 +48,28 @@ function isExoticComponent(component: any) {
|
|
|
59
48
|
)
|
|
60
49
|
}
|
|
61
50
|
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
66
|
-
|
|
67
|
-
export type UseTableInstanceOptions<TGenerics extends ReactTableGenerics> =
|
|
68
|
-
TableOptions<TGenerics>
|
|
69
|
-
|
|
70
|
-
export function useTableInstance<TGenerics extends ReactTableGenerics>(
|
|
71
|
-
table: Table<TGenerics>,
|
|
72
|
-
options: UseTableInstanceOptions<TGenerics>
|
|
73
|
-
): TableInstance<TGenerics> {
|
|
51
|
+
export function useReactTable<TData extends RowData>(
|
|
52
|
+
options: TableOptions<TData>
|
|
53
|
+
) {
|
|
74
54
|
// Compose in the generic options to the user options
|
|
75
|
-
const resolvedOptions: TableOptionsResolved<
|
|
76
|
-
...table.options,
|
|
55
|
+
const resolvedOptions: TableOptionsResolved<TData> = {
|
|
77
56
|
state: {}, // Dummy state
|
|
78
57
|
onStateChange: () => {}, // noop
|
|
79
|
-
render,
|
|
80
58
|
renderFallbackValue: null,
|
|
81
59
|
...options,
|
|
82
60
|
}
|
|
83
61
|
|
|
84
|
-
// Create a new table
|
|
85
|
-
const [
|
|
86
|
-
current:
|
|
62
|
+
// Create a new table and store it in state
|
|
63
|
+
const [tableRef] = React.useState(() => ({
|
|
64
|
+
current: createTable<TData>(resolvedOptions),
|
|
87
65
|
}))
|
|
88
66
|
|
|
89
|
-
// By default, manage table state here using the
|
|
90
|
-
const [state, setState] = React.useState(
|
|
91
|
-
() => instanceRef.current.initialState
|
|
92
|
-
)
|
|
67
|
+
// By default, manage table state here using the table's initial state
|
|
68
|
+
const [state, setState] = React.useState(() => tableRef.current.initialState)
|
|
93
69
|
|
|
94
70
|
// Compose the default state above with any user state. This will allow the user
|
|
95
71
|
// to only control a subset of the state if desired.
|
|
96
|
-
|
|
72
|
+
tableRef.current.setOptions(prev => ({
|
|
97
73
|
...prev,
|
|
98
74
|
...options,
|
|
99
75
|
state: {
|
|
@@ -108,5 +84,5 @@ export function useTableInstance<TGenerics extends ReactTableGenerics>(
|
|
|
108
84
|
},
|
|
109
85
|
}))
|
|
110
86
|
|
|
111
|
-
return
|
|
87
|
+
return tableRef.current
|
|
112
88
|
}
|