TanStackT
TanStack4y ago
1 reply
urgent-maroon

Integrate Tanstack table with array of array

Hi everyone. I got a type error when I tried to implement a table with an array of array data.
The typescript error message is as follows:
Type 'Bids' is not assignable to type 'Bids[]'.
  Type 'number[]' is not assignable to type 'Bids'.
    Type 'number' is not assignable to type 'number[]'.ts(2322)

And here is my implementation, Does anyone knows how to resolve this?
type Bids = Array<number[]>;

const defaultData: Bids = [
  [100, 2],
  [120, 4]
];

const columnHelper = createColumnHelper<Bids>();

const columns = [
  columnHelper.accessor((row) => `${row[0]}`, { id: "price" }),
  columnHelper.accessor((row) => `${row[1]}`, { id: "vol" })
];

.
.
.

const table = useReactTable({
    data: defaultData, // error show on this line
    columns,
    getCoreRowModel: getCoreRowModel()
  });

Sandbox link: https://codesandbox.io/s/compassionate-cherry-sn1u92?file=/src/main.tsx
CodeSandboxhypong
compassionate-cherry-sn1u92 by hypong using @tanstack/react-table, react, react-dom
compassionate-cherry-sn1u92 - CodeSandbox
Was this page helpful?