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