T
TanStack3y ago
constant-blue

columns from array of users

if i have a data structure like this:
type Data = {
name: string,
users: User[],
}
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]
);
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]
);
1 Reply
painful-plum
painful-plum3y ago
I guess something like that, but add id: user.id to the column def what's the use case?

Did you find this page helpful?