Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 第一次render()工作时未定义_React Native - Fatal编程技术网

React native 第一次render()工作时未定义

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} /&

在我的react原生应用程序中,我有以下代码

  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)=>)}