Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why render function not call in react?

I am trying to show my list in react using component .But it not display .I do like this

https://codesandbox.io/s/lYMwLM591

import { Component } from 'react';

class ImageSlider extends Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (<div>{this.props.data.hl}</div>);
  }
}

export default ImageSlider;

another components

 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>
    );
  }
}
like image 298
user5711656 Avatar asked Dec 04 '25 14:12

user5711656


1 Answers

The problem is pretty simple, you need to check the length of items array

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

And import React in ImageSlider component

import React, {Component} from 'react';

See this answer: Need help on React Js

DEMO

like image 57
Shubham Khatri Avatar answered Dec 07 '25 10:12

Shubham Khatri