i just started using react/redux and im facing a problem with async data handling, here i have the parent component (App) that im calling the action creator in to get the data and then passing it to the child component (VideoList)
`class App extends React.Component {
componentDidMount() {
this.onFormSubmit()
}
state = { selectedVideo: null }
onVideoClick = (video) => {
this.setState({selectedVideo: video});
};
onFormSubmit = (term) => {
this.props.fetchList(term)
}
render() {
return (
<div>
<Header/>
<div className="container">
<VideoDetail video={this.state.selectedVideo}/>
<VideoList videos={this.props.videos}/>
</div>
</div>
)
} }
const mapStateToProps = state => {
return {videos: state.videos} }
export default connect(mapStateToProps,{fetchList})(App)
`
now at the child component im trying to map over the videos array but it keeps telling me that map is not a function, i know that's because the data has not yet come from the youtube api so how can i solve this issue?
note: the app was perfectly functional before trying to setup redux
class VideoList extends React.Component {
renderList() {
this.props.videos.map(video => {
return <VideoItem video={video} onVideoClick={this.onVideoClick} key={video.id.videoId}/>
});
};
render() {
console.log(this.props.videos);
return (
<div>
{this.renderList()}
</div>
)
}
}
VideoListif the video list hasn't loaded yet would be a solution.