MCPcopy Index your code
hub / github.com/TanStack/table / useVueTable

Function useVueTable

packages/vue-table/src/index.ts:53–133  ·  view source on GitHub ↗
(
  initialOptions: TableOptionsWithReactiveData<TData>,
)

Source from the content-addressed store, hash-verified

51}
52
53export function useVueTable<TData extends RowData>(
54 initialOptions: TableOptionsWithReactiveData<TData>,
55) {
56 const IS_REACTIVE = isRef(initialOptions.data)
57
58 const resolvedOptions = mergeProxy(
59 {
60 state: {}, // Dummy state
61 onStateChange: () => {}, // noop
62 renderFallbackValue: null,
63 mergeOptions(
64 defaultOptions: TableOptions<TData>,
65 options: TableOptions<TData>,
66 ) {
67 return IS_REACTIVE
68 ? {
69 ...defaultOptions,
70 ...options,
71 }
72 : mergeProxy(defaultOptions, options)
73 },
74 },
75 IS_REACTIVE ? getOptionsWithReactiveData(initialOptions) : initialOptions,
76 )
77
78 const table = createTable<TData>(
79 resolvedOptions as TableOptionsResolved<TData>,
80 )
81
82 // Add reactivity support
83 if (IS_REACTIVE) {
84 const dataRef = shallowRef(initialOptions.data)
85 watch(
86 dataRef,
87 () => {
88 table.setState((prev) => ({
89 ...prev,
90 data: dataRef.value,
91 }))
92 },
93 { immediate: true },
94 )
95 }
96
97 // can't use `reactive` because update needs to be immutable
98 const state = ref(table.initialState)
99
100 watchEffect(() => {
101 table.setOptions((prev) => {
102 const stateProxy = new Proxy({} as typeof state.value, {
103 get: (_, prop) => state.value[prop as keyof typeof state.value],
104 })
105
106 return mergeProxy(
107 prev,
108 IS_REACTIVE
109 ? getOptionsWithReactiveData(initialOptions)
110 : initialOptions,

Callers

nothing calls this directly

Calls 3

mergeProxyFunction · 0.90
createTableFunction · 0.90

Tested by

no test coverage detected