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>) => {
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}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With