Answer the question
In order to leave comments, you need to log in
How to properly tell the Movie component that a particular movie is recommended?
state: https://dropmefiles.com/cGo3r
There are components:
Movie - displays a single movie
MovieList - displays a list of Movies
How can the Movie component know that this or that movie is recommended if the recommendations are a separate object and have only a link to the id?
App
class AppComponent extends React.PureComponent<AppComponentPropsType> {
render() {
return (
<React.Fragment>
<Header>
React Movie Cards
</Header>
<MovieList movies={this.props.movies} />
</React.Fragment>
);
}
}
export class MovieList extends React.PureComponent<MovieListPropsType> {
render() {
const { movies } = this.props;
return (
<div className="mt-5">
<div className="card-deck">
{movies && movies.map(movie => (
<Movie movie={movie} key={movie.id} />
))}
</div>
</div>
);
}
}
export class Movie extends React.PureComponent<MoviePropsType> {
render() {
const { movie } = this.props;
return (
<div className="movie-card">
<div className="movie-card card">
<img className="card-img-top" src={movie.imageUrl} alt={movie.title} />
<div className="card-body">
<h4 className="card-title">{movie.title}</h4>
<h6 className="card-subtitle mb-2 text-muted">{movie.subtitle}</h6>
<p className="text-justify movie-descr">{movie.description}</p>
</div>
<div className="card-footer">
<div className="clearfix">
<div className="float-left mt-1">
<StarRating rating={movie.rating} />
</div>
<div className="card-footer-badge float-right badge badge-primary badge-pill">{movie.rating}</div>
</div>
</div>
</div>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Essence:
The search can be performed in the selector, in the movies.map callback, memorized if necessary, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question