TanStackT
TanStack4y ago
2 replies
awake-maroon

columns from array of users

if i have a data structure like this:
type Data = {
  name: string,
  users: User[],
}

and i wanna render a column for each user, how would i do that? this was my idea but there's only one accessor key for "user"
const columns = React.useMemo(
    () => [
      columnHelper.accessor("name", {
        cell: (t) => t.getValue(),
        header: (t) => <span>Area</span>,
      }),
      ...users.map((user) =>
        //                     v- expect user.id maybe?
        columnHelper.accessor("user", {
          cell: (t) => t.getValue(),
          header: () => <span>{user.name}</span>,
        })
      ),
    ],
    [nested]
  );
Was this page helpful?