如何在 React Native 和 TS 中输入 prop 接收到的 renderItem Flatlist?
我有一个组件horizontallist
呈现以下内容:
<HorizontalList
data={categories}
renderItem={renderCategories}
titleList={'Categories'}
/>
这是我的组件文件,它接收以下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>
);
};
但我不知道哪种类型应该是renderitem
> prop,我尝试了()=&gt; jsx.element
,但在我收到错误:
Type '({ item }: { item: ICategorieItem; }) => JSX.Element' is not assignable to type '() => Element'.
I have a component HorizontalList
that render this:
<HorizontalList
data={categories}
renderItem={renderCategories}
titleList={'Categories'}
/>
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'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做;
或者,您可以从
react> react-native
中使用listrenderItem
。有关更多替代方案,请参阅此讨论。
当您还看到
RenderItem
和Data
Props的类型DEFS时,您会注意到那些接收到完全相同的通用类型的人的道具。You can do so;
or alternatively, you can make use of
ListRenderItem
fromreact-native
.For more alternatives, please see this discussion.
When you also see the type defs for
renderItem
anddata
props, you will notice that props of those receiving exact same generic type.