Reputation: 8585
For example export class FlatList<ItemT> extends React.Component<FlatListProps<ItemT>>
has ItemT
generic type in it. How do I use it in .tsx
code? Not parametrized looks like this:
<FlatList
data={this.state.data}
keyExtractor={this.keyExtractor}
renderItem={this.renderItem}
/>
But I would like my renderItem
method to have a specific class:
renderItem = (item: ListRenderItemInfo<DataItem>) => {
Upvotes: 4
Views: 5267
Reputation: 250266
Typescript 2.9 has added support to explicitly specify the type parameter to a tsx tag. This is the PR for this. So applying the syntax, it should be:
<FlatList<DataItem>
data={this.state.data}
keyExtractor={this.keyExtractor}
renderItem={this.renderItem}
/>
Upvotes: 4