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

Use generic by adding another type to interface in JSX

$
0
0

I came across an error that I don't know how to solve.

I have a generic component in React Native that takes a T value extending unknow.

However, inside this type T I'm sure I'll have a type called "name".

The question is...is there any way to use the generic type and, in addition, put the name as the default of T?

My code is this...

type GridProps<T> = {  data: T[];};export function Grid<T extends unknown>({ data }: GridProps<T>) {  const { sizes } = useTheme();  return (<><GridHeader><Text content={`Encontrados ${data.length} items.`} color="gray-400" /></GridHeader><FlashList        numColumns={2}        data={data}        estimatedItemSize={data.length}        renderItem={({ item, index }) => (<GridItem            style={              index % 2 === 0                ? { marginRight: sizes[2] }                : { marginLeft: sizes[2] }            }><Text content={item.name} /></GridItem>        )}      /></>  );}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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