So I have a flatlist as a custom component and I use it in App
component. However in App
, item
parameter of renderItem
has unknown
type. I know this is an expected behavior but I am not sure how to use generics in CustomFlatList
.
import React, { forwardRef } from "react"import { FlatList, FlatListProps, Text, View } from "react-native"interface Props<T> { flatListProps: FlatListProps<T>}const CustomFlatList = forwardRef<any, Props<unknown>>((props, ref) => { return (<View><FlatList {...props.flatListProps} /></View> )})const App: React.FC = () => { return <View><CustomFlatList flatListProps={{ data: [1, 2, 3], renderItem: ({ item }) => <Text>{item}</Text> // item type is unknown here }} /></View>}export default App