4

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>) => {
1
  • Do you mind sharing what you return from the renderItem function? Commented Oct 7, 2018 at 15:45

1 Answer 1

4

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}
    />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.