T
TanStack17mo ago
correct-apricot

Can't access accessorKey when mapping ColumnDef array

Trying to map over columns to change the cell property based on a selected value in the component but the accessorKey property isn't accessible. If I log the items out while mapping, there's clearly an accessorProperty. I read the reason why it's not but I'm not sure what to do. Is there a better way to do this? Am I supposed to be doing this in the component rather than the columns? I feel like I should be able to render the content dynamically via the columns property. Is my only recourse to use the header property?
2 Replies
harsh-harlequin
harsh-harlequin17mo ago
I think you can use the accessorKey in the columnHelper columnDefs, but not plain column defs. This is because typescript doesn't know if an accessorKey or accessorFn was defined in the normal ColumnDef type. It's mostly recommended to reference the id instead of accessorKey anyway though, since the id will be derived from the accessorKey
correct-apricot
correct-apricotOP16mo ago
In other news I’m really dumb. I can just map the array before I give it a type. Thank you for the response!

Did you find this page helpful?