Hello, I'm building a compound React component (e.g. Table, Table.Row, Table.Cell). The parent component (e.g. Table) has a config prop that should infer the type of the provided configuration. However, I'm having trouble making this work.
Here's the call site
// call-site.tsx
<Table options={myOptions}>
<Table.Row>...</Table.Row>
</Table>
and here's the compound table component that needs Options as a generic
// table.tsx
type TableProps<Options extends {}> = {
// table parent props
}
??? how can TableProps accept a generic from the call site ???
type TableComponent = FC<TableProps> & {
Row: typeof CollectionFilters
}
??? how can TableComponent accept a generic from the call site ???
export const Table: TableComponent = ({
options,
children,
}) => (
<TableProvider options={options}>
{children}
</TableProvider>
)
Table.Row = TableRow
Is it possible to use generics in a compound component like this?