I'm trying to render a card list with react-virtualized. The posts data on this particular component is passed as a prop from the parent. This is what I currently have in my component class.
state = {
listHeight: 1000,
listRowHeight: 800,
listRowWidth: 1000,
rowCount: 10
}
rowRenderer ({ index, key, style, posts }) {
if (!posts) {
return <div></div>
} else {
return (
<PostItem key={key} style={style} post={posts[index]}/>
);
}
}
render() {
return (
<div className="ui container">
<div id="postListContainer" className="ui relaxed list">
<List
width={this.state.listRowWidth}
height={this.state.listHeight}
rowHeight={this.state.listRowHeight}
rowRenderer={this.rowRenderer}
rowCount={this.state.rowCount}
posts={this.props.posts}
/>
</div>
</div>
);
}
}
I hardcoded the rowCount since I know I have 10 items in my posts array currently. Just for context, this was my original code that renders the entire list successfully.
renderPosts() {
return this.props.posts.map(post => {
return (
<PostItem key={post._id} post={post}/>
);
})
}
render() {
return (
<div className="ui container">
<div id="postListContainer" className="ui relaxed list">
{this.renderPosts()}
</div>
</div>
);
}
}
The issue i'm currently having is that I can't access the props passed down into this component from my rowRenderer function so it gives me an undefined error. So my question is, how do I access the posts props in the rowRenderer function? I'm just trying to return a PostItem component for each post in the posts prop array.