Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
How to typing renderItem Flatlist received by prop in react native and TS?

I have a component HorizontalList that render this:

<HorizontalList
  data={categories}
  renderItem={renderCategories}
  titleList={'Categories'}
/>

enter image description here

this is my component file that receives the following props

//HorizontalList.tsx

interface Props {
  titleList: string;
  data: object[];
  renderItem: <--- //IDK what type should be here;
}

const HorizontalList: React.FC<Props> = ({titleList, data, renderItem}) => {
  return (
    <View style={styles.root}>
      <Text style={styles.titleText}>{titleList}</Text>
      <FlatList horizontal data={data} renderItem={renderItem} />
    </View>
  );
};

but I dont know what type should be renderItem prop, I tried with () => JSX.Element , but in I get the error:

Type '({ item }: { item: ICategorieItem; }) => JSX.Element' is not assignable to type '() => Element'.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do so;

  interface Props {
    titleList: string;
    data: ICategorieItem[];
    renderItem: ({
      item: ICategorieItem,
      index: number,
    }) => React.ReactElement;
  }

or alternatively, you can make use of ListRenderItem from react-native.

For more alternatives, please see this discussion.

    // data prop type definition for FlatList

    data: ReadonlyArray<ItemT> | null | undefined;

    // renderItem prop type definition
    renderItem: ListRenderItem<ItemT> | null | undefined;


When you also see the type defs for renderItem and data props, you will notice that props of those receiving exact same generic type.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!