Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to type a component which has flatlist with forwadRef in React?

$
0
0

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

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>