Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fetchMovies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const FetchMovies = () => {

const sortById = (list) => list.sort((a, b) => a.id - b.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sortById라는 함수를 통해 인덱스를 삭제하면 해당 함수 호출을 통한 정렬을 편리하게 구현하셨군요!


const addWatched = (movie) => {
const addWatchedList = (movie) => {
setWatched((prev) => sortById([...prev, movie]));
setMovies((prev) => sortById(prev.filter((m) => m.id !== movie.id)));
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

영화를 오름차순으로 정렬하고, 제거 후 원래 리스트에 추가되도록 코드를 깔끔히 잘 작성하셨네요!

Expand Down Expand Up @@ -103,7 +103,7 @@ const FetchMovies = () => {
<div>{movie.description}</div>
<div className="just">
<button
onClick={() => addWatched(movie)}
onClick={() => addWatchedList(movie)}
className="bg-white hover:bg-gray-500 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded mt-4 mr-3">
시청한 영화 담기
</button>
Expand Down