@tanstack/react-table 9.0.0-alpha.0 → 9.0.0-alpha.11

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/src/index.tsx DELETED
@@ -1,94 +0,0 @@
1
- import * as React from 'react'
2
- export * from '@tanstack/table-core'
3
-
4
- import {
5
- TableOptions,
6
- TableOptionsResolved,
7
- RowData,
8
- createTable,
9
- } from '@tanstack/table-core'
10
-
11
- export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>
12
-
13
- //
14
-
15
- /**
16
- * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.
17
- */
18
- export function flexRender<TProps extends object>(
19
- Comp: Renderable<TProps>,
20
- props: TProps
21
- ): React.ReactNode | JSX.Element {
22
- return !Comp ? null : isReactComponent<TProps>(Comp) ? (
23
- <Comp {...props} />
24
- ) : (
25
- Comp
26
- )
27
- }
28
-
29
- function isReactComponent<TProps>(
30
- component: unknown
31
- ): component is React.ComponentType<TProps> {
32
- return (
33
- isClassComponent(component) ||
34
- typeof component === 'function' ||
35
- isExoticComponent(component)
36
- )
37
- }
38
-
39
- function isClassComponent(component: any) {
40
- return (
41
- typeof component === 'function' &&
42
- (() => {
43
- const proto = Object.getPrototypeOf(component)
44
- return proto.prototype && proto.prototype.isReactComponent
45
- })()
46
- )
47
- }
48
-
49
- function isExoticComponent(component: any) {
50
- return (
51
- typeof component === 'object' &&
52
- typeof component.$$typeof === 'symbol' &&
53
- ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
54
- )
55
- }
56
-
57
- export 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
- }