React native 如何使函数呈现列表项

React native 如何使函数呈现列表项,react-native,React Native,我有两个类,分别是FlatListItem和HobbyList,用于显示爱好列表。但现在我只想使用一个类HobbyList。我想在类HobbyList中创建一个函数renderItem,以便像类FlatListItem一样进行渲染。我该怎么做 类FlatListItem扩展组件{ render(){ const{checked}=this.state; 返回( this.onClick(选中)}> this.onClick(选中)} > {this.props.item.name} ); } }

我有两个类,分别是FlatListItem和HobbyList,用于显示爱好列表。但现在我只想使用一个类HobbyList。我想在类HobbyList中创建一个函数
renderItem
,以便像类FlatListItem一样进行渲染。我该怎么做

类FlatListItem扩展组件{
render(){
const{checked}=this.state;
返回(
this.onClick(选中)}>
this.onClick(选中)}
>
{this.props.item.name}
);
}
}
导出默认类HobbyList扩展组件{
构造函数(){
超级()
}
renderItem({item,index}){
//在此呈现列表
}
render(){
返回(
{
如果(item.empty==true){
返回
}
返回
}}
>
);
}
}

我认为您想要的是将renderItem作为一个函数进行介绍。那么你就不必把它归类为
。您可以制作一个
函数
并使用它

this.state={checked:true}
...
_renderItem=({item})=>(
this.onClick(选中)}>
this.onClick(选中)}
>
{item.name}
);
...