Why this is not working ?
const List: <ListItem> = ({ items, render }: {
items: ListItem[],
render: (item: ListItem) => React.ReactNode
}) => {
return (
<View>
{ items.map((el, i) => (
<Text key={i}>{render(el)}</Text>
)) }
</View>
)
};
Error:
TransformError SyntaxError: C:\RNT\TS\ts\App.tsx: Unexpected token, expected "(" (54:23)
CodePudding user response:
That's not the correct syntax. A generic function has it's generic parameter just before the opening (
character.
That would probably look like this:
const List = <ListItem>({ items, render }: {
items: ListItem[],
render: (item: ListItem) => React.ReactNode
}) => {
//...
};