6 - Dynamic Movie List with Filtering and Sorting
Description
Create a React application that displays a dynamic list of movies. The application should allow users to filter movies by genre and sort movies by title or release year.
Algorithm
Initialize a state variable to store the list of movies.
Render a list of movies with filters and sort options.
Define functions to filter movies by genre and sort movies by title or release year.
Update the movie list based on user input.
Classes
MovieList
: A React component that manages the movie list state and renders the movie list, filters, and sort options.
Code
Explanation
The code defines a MovieList
component that utilizes the useState
hook to initialize state variables for the movie list, filter genre, and sort option. The component renders a list of movies, filters, and sort options. The handleFilterChange
and handleSortChange
functions update the filter genre and sort option state variables, respectively. The filteredMovies
and sortedMovies
variables are calculated based on the user input, and the sorted movie list is rendered.
Possible Future Enhancements
Add more filter options (e.g., release year, director).
Implement a search bar to search movies by title or description.
Display movie details (e.g., plot, cast) when a movie is selected.
Integrate with a movie database API to fetch movie data dynamically.
Last updated