T
TanStack3y ago
fuzzy-lavender

is there a way to extend CellContext/HeaderContext types

I want to add some information to the context, so that the function in cell/header can use it. in my specific case the table is operating on item ids only, and I'd like to get the item when I render the row and pass it to the cell render function
4 Replies
rival-black
rival-black3y ago
I've used a pattern a bit like that before. I just decided not to use flexRender at all. Instead you can just take more direct control over what is rendered (and which props you pass to it). Is this intended to be a perf optimisation (stateful cells which lookup a value from an external store)?
fuzzy-lavender
fuzzy-lavenderOP3y ago
thanks, that sounds not bad. and yes, it is. but.. unfortunately in order for the types system not to go crazy, I need to add properties to the column definition. in general the types in the table are tough, for example, the id has to be a string (number is killing it)
rival-black
rival-black3y ago
Can you share any example of the properties you are adding to the column definition? I set something similar up without needing to do that.
fuzzy-lavender
fuzzy-lavenderOP3y ago
@shreake sorry that it took me so long.. here is a sandbox https://codesandbox.io/s/table-types-9knfrv?file=/src/components/Table.tsx btw, if we are talking about types... there is another annoying part about expanded rows, the table doesn't really recognize the idea that the main row and the expanded row might have different types

Did you find this page helpful?