我正在尝试找出 React 中的条件渲染。如果用户的监视列表中没有电影,我只想输出一个标题。我认为这样的事情会起作用:
render() {
return (
<Container>
{this.state.watchlist.map(item => {
if(this.state.watchlist.length > 0) {
return (
<WatchlistMovie
className="watchlist-movie"
key={item.id}
id={item.id}
title={item.title}
poster={item.poster}
overview={item.overview}
rating={item.rating}
user={this.props.user}
/>
);
} else {
return <h1>no movies</h1>
}
)}}
</Container>
);
}