I have the following code, and I want to add an even handler for detecting when delete button is clicked and then remove the specific item from list.
Favorites.js
constructor(props) {
super(props);
this.state = {
movies: []
};
this.clearSaved = this.clearSaved.bind(this);
this.handleDelete = this.handleDelete.bind(this);
}
MovieList.js
export default ({ movies }) => {
return(
<div id="saved-movies-list">
<ul className="saved-movies-list">
{ movies.map(movie => <li key={ movie.imdbID }><Movie movie={ movie } /></li>) }
</ul>
</div>
)
};
Movie.js
const Movie = ({movie}) => {
return (<div className="movie-card" id={movie.imdbID}>
{
// eslint-disable-next-line
movie.poster == 'N/A' ?
<div className="movie-card-poster missing">
<img className="d-block h-100" src={movie_poster} alt="" />
</div>
:
<div className="movie-card-poster">
<img className="d-block h-100" src={movie.poster} alt="" />
</div>
}
<div className="body">
<div style={{ maxWidth: '80%' }}>
<h5 class="card-title">{movie.title}</h5>
</div>
<p className="text-secondary">{ movie.year }</p>
{!movie.runtime ? "" : <p className="text-secondary">{ movie.runtime }</p>}
<p className="plot">{movie.description}</p>
<a href="#" className="delete-movie" title="Remove this movie"><FontAwesomeIcon icon="minus-circle" size="1x" /></a>
</div>
</div>)
}
I need to attach event to this line:
<a href="#" className="delete-movie" title="Remove this movie"><FontAwesomeIcon icon="minus-circle" size="1x" /></a>
But, I do NOT know how to? Writing this.props. ... does not work!