React native 第一次render()工作时未定义
在我的react原生应用程序中,我有以下代码React native 第一次render()工作时未定义,react-native,React Native,在我的react原生应用程序中,我有以下代码 render() { return ( <Swiper height={height} showsButtons={true} showsPagination={false}> this.props.features.forEach(feature => { <SwiperSlider imageSource={feature.featureImage} /&
render() {
return (
<Swiper height={height} showsButtons={true} showsPagination={false}>
this.props.features.forEach(feature => {
<SwiperSlider imageSource={feature.featureImage} />
});
</Swiper>
);
}
render(){
返回(
this.props.features.forEach(feature=>{
});
);
}
这给了我一个错误,“未定义特征”。
第一次运行render()时,features数组为空。如何解决这个问题?您应该使用
map
并用大括号括起来
<Swiper height={height} showsButtons showsPagination={false}>
{this.props.features.map((feature) => <SwiperSlider imageSource={feature.featureImage} />)}
</Swiper>
{this.props.features.map((feature)=>)}