Reactjs 为什么渲染函数不在react中调用?

Reactjs 为什么渲染函数不在react中调用?,reactjs,react-native,react-router,react-redux,Reactjs,React Native,React Router,React Redux,我试图在react中使用组件显示我的列表。但它不显示。我喜欢这样 从'react'导入{Component}; 类ImageSlider扩展组件{ 建造师(道具){ 超级(道具); } render(){ 返回({this.props.data.hl}); } } 导出默认图像滑块; a其他组件 renderStories() { if (this.props.stories && this.props.stories.items > 0) { r

我试图在react中使用组件显示我的列表。但它不显示。我喜欢这样

从'react'导入{Component};
类ImageSlider扩展组件{
建造师(道具){
超级(道具);
}
render(){
返回({this.props.data.hl});
}
}
导出默认图像滑块;
a其他组件

 renderStories() {
    if (this.props.stories && this.props.stories.items > 0) {
      return this.props.stories.items.map(story => {
        return <ImageSlider data={story}/>;
      });
    }
  }
  render() {
    return (
      <div>
        lll
        {this.renderStories()}
      </div>
    );
  }
}
renderStories(){
if(this.props.stories&&this.props.stories.items>0){
返回此.props.stories.items.map(story=>{
返回;
});
}
}
render(){
返回(
微光
{this.renderStories()}
);
}
}
更改:

renderStories() {
  if (this.props.stories && this.props.stories.items > 0) {
    return this.props.stories.items.map(story => {
      return <ImageSlider data={story}/>;
    });
  }
}

你也必须这样做


导入React,{Component}from'React;

问题很简单,您需要检查
项目长度数组

if (this.props.stories && this.props.stories.items.length > 0) {
  return this.props.stories.items.map(story => {
    return <ImageSlider data={story}/>;
  });
}
看看这个答案:

renderStories() {
  if (this.props.stories && this.props.stories.items && this.props.stories.items.length > 0) {
    return this.props.stories.items.map(story => {
      return <ImageSlider data={story}/>;
    });
  }
}
import React, { Component } from 'react';
if (this.props.stories && this.props.stories.items.length > 0) {
  return this.props.stories.items.map(story => {
    return <ImageSlider data={story}/>;
  });
}
import React, {Component} from 'react';